
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
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
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
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
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










Other popular topics










Latest in Backend
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /c
- /slackware
- /julia
- /neovim