Can you set the boolean value directly via mix command?

Can you set the true or false value for boolean table field directly via mix command?

For example, I have this command:

$ mix phx.gen.context Cars Car cars model:string

but I want to add a field called sold and the default value will be true instead of the default false valueprovided by Phoenix/Ecto.

I have tried to check it here: Mix.Tasks.Phx.Gen.Context – Phoenix v1.3.0-rc.1

But there is nothing like what I want at all.

Is it possible? Or you have to do it later manually?

I have tried this:

$ mix phx.gen.context Cars Car cars model:string sold:boolean:true

But I got this error back:

** (Mix) Unknown type true given to generator

Any idea how to do that?

You need to create migration first, something like mix ecto.gen.migration cars_add_sold_column

This will generate a migration file, in which you need to adjust the change function to your needs. It should contain something like add :sold, :boolean, default: true

See also here + the link to docs from there> elixir - How to add field in existing table phoenix - Stack Overflow

You cannot set default values directly from the CLI. You can find detailed documentation on the available options here: mix phx.gen.schema — Phoenix v1.6.5

Generally the CLI is not meant to be a tool to generate all the code you might possibly need, but only to create common boilerplate according matching the structure phoenix guides explain. There will always be modifications left to do by hand after using the generators. I even think they loose their usefulness completely when a project grows as strict structure gets harder to maintain.