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?
As @ChillarAnand noted there is a ticket solving this issue but until now (django 1.9.1) the migrations commands were not fixed.
The least intrusive way of fixing it is to create your own
maketranslatedmigrations
command in<your-project>/management/commands/maketranslatedmigrations.py
asAnd then you can use it exactly the same as original makemigrations.
P.S. Don't forget to add
__init__.py
files everywhere on the pathThis 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.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
andmigrate
command by putting this inmanagement/commands/makemigrations.py
in your app:To avoid unnecessary migrations You can do as follows:
Example:
Hope that helps
I have written custom module for that purpose
All you need is to save it in some utils/models.db and in all your models instead of
from django.db import models
writefrom utils import models
If somebody is interested in it I can write a component and publish it on pypi
UPD: try this https://github.com/FeroxTL/django-migration-control
# models.py
The ticket that ChillarAnand mentions is very helpfull, but at final of changelog, I did not realize if it was fixed or not, or it was fixed in newest version of Django.
So, due to I did not found any solution for Django 1.9.13, I added a little hack to
settings.py
:Not elegant, but it works ok.