The --no-migration flag, does not prevent the generation of mirgrations when used with phx.gen.context

It is stated that the default gen settings can be overridden with use of appropriate options,

Default options

This generator uses default options provided in the :generators configuration
of your application. These are the defaults:

config :your_app, :generators,
  migration: true,
  binary_id: false,
  timestamp_type: :naive_datetime,
  sample_binary_id: "11111111-1111-1111-1111-111111111111"

You can override those options per invocation by providing corresponding
switches, e.g. --no-binary-id to use normal ids despite the default
configuration or --migration to force generation of the migration.

however preventing the generation of a migration using the --no-migration key does not seem to work.

mix phx.gen.context Testex Testa testas --no-migration
* creating lib/schem_exp/testex/testa.ex
* creating priv/repo/migrations/20250210111130_create_testas.exs
* creating lib/schem_exp/testex.ex
* injecting lib/schem_exp/testex.ex
* creating test/schem_exp/testex_test.exs
* injecting test/schem_exp/testex_test.exs
* creating test/support/fixtures/testex_fixtures.ex
* injecting test/support/fixtures/testex_fixtures.ex

Remember to update your repository by running migrations:

    $ mix ecto.migrate

Then I discard the generated files via version control and run again with phx.gen.context, get the same result. Do the discard again and this time run with phx.gen.schema:

mix phx.gen.schema Testa testas --no-migration
* creating lib/schem_exp/testa.ex

No migration generated.

Is it the case that migration generation with contexts can only be prevented by amending the defaults ? (doing does indeed actually prevent migration generation)

It doesn’t look like phx.gen.context has a migration flag. But phx.gen.schema does.

Couldn’t tell you why.

1 Like

I think it parses the opts using the phx.gen.context switches before passing the parsed opts to phx.gen.schema.

But since the phx.gen.context switches don’t include a migration flag it gets removed before the schema is generated (with the migration).

That should probably be considered a bug. Maybe open an issue?

1 Like

Might be a bug, context schemas are contained with the context dir so it’s a compartmentalisation feature but migration duplication just yield errors.

Issue submitted