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

Kurisu
Hello, Please, let’s say I have a website with user authentication made with Elixir/Phoenix, and now want to add a forum to it (using a ...
New
Jsdr3398
Are there any databases that require no setup (can be shipped in a small zip together with the project)?
New
Ookma-Kyi
I am learning Elixir at the moment but am finding it difficult to learn. The issue is there aren’t any good tutorial sites out there when...
New
Fl4m3Ph03n1x
Background I am trying out polymorphic typing with dialyzer. As an example I am using the famous Option type (aka, Maybe Monad) that is n...
New
JimmyCarterSon
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...
New
sona11
I studied very basic PHP (I believe). After that, I feel like I’ve gotten a handle on the language. My dream is to work as a web develope...
New
Fl4m3Ph03n1x
Background I have a phoenix application in Windows 11. Unfortunately for me, I cannot compile the application because of a dependency err...
New
harwind
I’m presently working on a backend development project to build a RESTful API using Python and Flask. The Scaler backend developer site h...
New
harwind
I have a large SQL database with millions of records, and I’ve identified duplicate entries. What’s the most efficient way to find and re...
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

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in Questions

View all threads ❯