Since Django 1.8 the makemigrations
command has a --name, -n
option to specify custom name for the created migrations file.
I'd like to know whether it's safe in older versions of Django to create the migrations file with the automatically generated name and then rename the file manually. It seems to work as expected. Are there any potential risks?
Deleting migration files means losing your history. This historical info is recorded in the django_migrations table in your database. if you delete migration files, you will get dependency errors. So Don't try to lose your history by deleting your migration files.
In the current version of Django you can rename the model and run python manage.py makemigrations , django will then ask if you want to rename the model and if you select yes, then all renaming process will be done automatically.
Migrations are not required. They can be useful for creating and tracking database changes via code, but Django applications will run properly without them.
This works, with a minor caveat: Django will no longer know that the renamed migration is applied.
So the steps to renaming a migration are:
--fake
. If it's a brand new migration, 2 and 3 won't apply, and it's perfectly fine to rename them.
This is happens in Django every time migrations are squashed. A new file is generated thats contains the class variable replaces
, this lists the migration files that are being replaced.
So to rename a file migration file add in the following variable in the Migration class:
replaces = [('app name', 'migration file name'), ]
And everything works like it did before the file change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With