When I change help_text
or verbose_name
for any of my model fields and run python manage.py makemigrations
, it detects these changes and creates a new migration, say, 0002_xxxx.py
.
I am using PostgreSQL and I think these changes are irrelevant to my database (I wonder if a DBMS for which these changes are relevant exists at all).
Why does Django generate migrations for such changes? Is there an option to ignore them?
Can I apply the changes from 0002_xxxx.py
to the previous migration (0001_initial.py
) manually and safely delete 0002_xxxx.py
?
Is there a way to update previous migration automatically?
Django will make migrations for any change to your models or fields - even options that don't affect the database - as the only way it can reconstruct a field correctly is to have all the changes in the history, and you might need those options in some data migrations later on (for example, if you've set custom ...
Migrations are not required. They can be useful for creating and tracking database changes via code, but Django applications will run properly without them.
You can squash it with the previous migration, sure.
Or if you don't want to output those migrations at all, you can override the makemigrations
and migrate
command by putting this in management/commands/makemigrations.py
in your app:
from django.core.management.commands.makemigrations import Command from django.db import models IGNORED_ATTRS = ['verbose_name', 'help_text', 'choices'] original_deconstruct = models.Field.deconstruct def new_deconstruct(self): name, path, args, kwargs = original_deconstruct(self) for attr in IGNORED_ATTRS: kwargs.pop(attr, None) return name, path, args, kwargs models.Field.deconstruct = new_deconstruct
This ticket addressed the problem.
If you have changed only help_text
& django generates a new migration; then you can apply changes from latest migration to previous migration and delete the latest migration.
Just change the help_text
in the previous migration to help_text present in latest migration and delete the latest migration file. Make sure to remove corresponding *.pyc
file if it is present. Otherwise an exception will be raised.
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