JimmyCarterSon

JimmyCarterSon

Assistance with Schema Mix

I am confused about the Schema setup,

I am setting up a new application and I want to seed files in it as well. I tried to mix to create the schema mix phx.gen.html Delish.food delish_foods title:string ingredients:string summary:string date:integer
I keep getting this error even if I try phx.gen.schema, the error looks like this

** (Mix) Expected the context, "Delish.food", to be a valid module name

mix phx.gen.html, phx.gen.json, phx.gen.live, and phx.gen.context
expect a context module name, followed by singular and plural names
of the generated resource, ending with any number of attributes.
For example:

    mix phx.gen.html Accounts User users name:string
    mix phx.gen.json Accounts User users name:string
    mix phx.gen.live Accounts User users name:string
    mix phx.gen.context Accounts User users name:string

The context serves as the API boundary for the given resource.
Multiple resources may belong to a context and a resource may be
split over distinct contexts (such as Accounts.User and Payments.User).

Do I just set up the schema with one title:string?

Marked As Solved

AntonRich

AntonRich

I see. I got a bit confused and thought you wanted to only create Schema, but you’re trying to create Context and Schema.

mix phx.gen.html Foods Food delish_foods title:string ingredients:string summary:string date:integer

Foods - Context Module
Food - Schemade module
delish_foods - table name

It will create:

  • a context module in lib/app/foods.ex for the accounts API
  • lib/app/foods - folder
  • lib/app/foods/food.ex - schema module

It will also create templates, views, and a controller. It will show all the files it created in the terminal.

Also Liked

AntonRich

AntonRich

mix phx.gen.html - a command that will generate Context module and Schema
https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Html.html

while
mix phx.gen.schema - will generate Schema
https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Schema.html

P.S. Sorry, posted too early. You already mentioned using mix pxh.gen.schema
P.P.S I think it’s supposed to be mix phx.gen.schema Delish.Food - ‘food’ should be started with a capital latter to indicate a module.

JimmyCarterSon

JimmyCarterSon

I am still getting the same error

** (Mix) Expected the schema, "delish_foods", to be a valid module name

mix phx.gen.html, phx.gen.json, phx.gen.live, and phx.gen.context
expect a context module name, followed by singular and plural names
of the generated resource, ending with any number of attributes.
For example:

    mix phx.gen.html Accounts User users name:string
    mix phx.gen.json Accounts User users name:string
    mix phx.gen.live Accounts User users name:string
    mix phx.gen.context Accounts User users name:string

The context serves as the API boundary for the given resource.
Multiple resources may belong to a context and a resource may be
split over distinct contexts (such as Accounts.User and Payments.User).
JimmyCarterSon

JimmyCarterSon

Could you give me an example using this mix phx.gen.html Delish.food delish_foods title:string ingredients:string summary:string date:integer? on how the two mix commands are different?

Popular Backend topics Top

PragmaticBookshelf
Don’t accept the compromise between fast and beautiful: you can have it all. Phoenix creator Chris McCord, Elixir creator José Valim, and...
New
PragmaticBookshelf
You want increased customer satisfaction, faster development cycles, and less wasted work. Domain-driven design (DDD) and functional prog...
New
AstonJ
Another BEAM language… The Hamler Programming Language Hamler is a strongly-typed language with compile-time typechecking and built-in...
New
New
mafinar
A friend and I implemented a few algorithms in Dart and set them up in a repository. Thought I’d share it here.
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
GermaVinsmoke
Reading Programming Elixir 1.6 book, I’ve completed part 1 of the book. Now I’m thinking of reading Elixir in Action. What do you all sug...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
First poster: OvermindDL1
Today we are happy to announce axum: An easy to use, yet powerful, web framework designed to take full advantage of the Tokio ecosystem. ...
New
sampu
I have a use case where a client is invoking a Rest endpoint via a load balancer, which in turn invokes a third party endpoint which is r...
New

Other popular topics Top

DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1122 25133 743
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New