djangomakemigrations

Can you stop Django automatically reverting a manual Migration?


I have a Model file which has a change which isn't being picked up by DJango makemigrations.

I created a manual migration following this answer, but if we run makemigrations afterwards Django creates a new auto migration reverting our manual changes.

Is there a way to manually make a migration and tell DJango to ignore relevant parts of the code when generating future migrations?


Solution

  • After making changes to the models and creating a custom migration for them e.g. using RunPython or RunSQL you can use the state_operations argument to reflect the changed models' state in your custom Python or SQL operations.