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?

Where Next?

Popular Backend topics Top

dimitarvp
As a part of my new job I’ll have to learn to manage a local k8s cluster. The tools used are microk8s, tilt and helm. I’ll appreciate an...
New
New
wolf4earth
At work we plan to replace a totally overkill Kafka instance with a combination of SNS and SQS. I don’t want to get into a discussion on ...
New
joshi
Hey everybody! I’m working on the project that includes import of Oracle data to PostgreSQL. That data comes as Oracle export (expdp) fi...
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
bsek43
Hello everyone, I’ve started learning Elixir and Phoenix few months ago and while I mostly grasped Elixir’s functional concepts and Phoe...
New
Fl4m3Ph03n1x
Background I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it. Howeve...
New
Fl4m3Ph03n1x
Background I have a personal project that is an elixir desktop application for PC Windows. It works pretty well, but now I want to give i...
New
harwind
I received this error for a binary search programme in C, despite the fact that it requested for inputs and produced the right output. Th...
/c
New
Fl4m3Ph03n1x
Background I have an umbrella project, where I run mix test from the root. In one of the apps, I am mocking the File module using the Mo...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1023 17214 380
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New