Just as you did, but using types that are understood by the generator.
The error message clearly states that the generator doesn’t know about the type smallint
and tells you which types it knows about, among them is integer
, probably the closest to smallint
.
Besides of that, writing some bits of text explaining your actual problem and what you would expect to happen are considered nice things, also copy-pasted code/terminal outputs are much easier to consume on mobiles and/or screenreaders than screenshots are.
Besides of that, writing some bits of text explaining your actual problem and what you would expect to happen are considered nice things, also copy-pasted code/terminal outputs are much easier to consume on mobiles and/or screenreaders than screenshots are.
Sorry for that. Worked a day and tired so did that.
Here is my actual question:
when I use
mix phx.gen.context School Course courses --table api_courses cover:string title:string subtitle:string issue:smallint
It give me this error:
** (Mix) Unknown type `:smallint` given to generator.
As I known, :smallint
can use in the migration file, why mix phx.gen.context
didn’t know that?
When I type this gen, I expect I will see
field :issue, :integer
in the schema file, and see add :issue, :smallinit
in the migration file.
Is there some way to get it .
The types from the migration are passed to the database literally, and phoenix/ecto decided to use a common subset. smallint
is not part of that as it seems.
You need to revise your migration files manually in such cases.
There are various sets of types in ecto:
- Primitive types (https://hexdocs.pm/ecto/3.0.4/Ecto.Schema.html#module-primitive-types)
- Custom types (https://hexdocs.pm/ecto/3.0.4/Ecto.Schema.html#module-custom-types)
They all convert down to Primitive types - (Database column types)
The generators work with the primitive types (not sure about {:map, type}
and {:array, type}
though). In the migration you can use any column type your database supports, while when using the primitive types of ecto it does simply use a sensible default. The other way around there’s no knowledge in ecto. It does not know a :smallint
should be made a :integer
in the schema and you need the primitive type to generate the schema.
OK, thanks, I will revise my migration files manually.