为什么Django会生成help_text和verbose_name更改的迁移? [英] Why does Django generate migrations for help_text and verbose_name changes?
问题描述
当我为任何我的模型字段更改 help_text
或 verbose_name
并运行 python manage.py makemigrations
,它会检测到这些更改,并创建一个新的迁移,例如 0002_xxxx.py
。
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
.
我使用PostgreSQL,我认为这些更改与我的数据库无关(我想知道这些更改相关的DBMS是否相关)。
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).
为什么Django会为此类更改生成迁移?是否可以忽略它们?
Why does Django generate migrations for such changes? Is it an option to ignore them?
我可以将 0002_xxxx.py
中的更改应用到以前的迁移 0001_initial.py
)手动并安全地删除 0002_xxxx.py
?
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?
推荐答案
这张票解决了这个问题。
如果您只更改了 help_text
& django生成新的迁移;那么您可以将最新迁移的更改应用到以前的迁移,并删除最新的迁移。
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.
只需将 help_text
以前迁移到最新迁移中的help_text,并删除最新的迁移文件。确保删除相应的 *。pyc
文件(如果存在)。否则会引起例外。
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.
这篇关于为什么Django会生成help_text和verbose_name更改的迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!