Django迁移删除和更新 [英] Django migration delete and update
问题描述
我已经有了一些迁移文件,并且对模型进行了一些更改并做了
I have already had some migration files, and I made some changes in the model and did
python manage.py makemigrations
python manage.py migrate
之后,在PostgreSQL表django_migrations中,有一行指示已经应用了该迁移,我们称之为迁移A。
我删除了新生成的迁移文件(migrationA),修改了模型中的一小部分,然后做了
After that in postgresql table django_migrations there is a row indicating I've applied that migration, let's call this migrationA. I deleted the new generated migration file (migrationA), modified a small piece in my model and then did
python manage.py makemigrations
python manage.py migrate
这会生成migrationB。我希望这可以像压缩迁移文件一样。
This generate migrationB. I was hoping this can do the same as squashing migration files.
这种流程会带来麻烦吗?我现在没有遇到任何麻烦,但想确保这是一种安全的方法。另外,有什么方法可以将postgresql还原为我应用migrationA之前的时间吗?
Will this kind of flow cause any trouble? I didn't see any trouble now but want to make sure this is a safe way to do things. In addition, is there any way to revert postgresql to the time before I applied migrationA?
推荐答案
是的,这会造成麻烦。所有迁移都存储在迁移表中,仅删除迁移会在您的实际迁移和所记录的记录之间产生不一致。
Yes, it will cause trouble. All the migrations are stored in the migrations table and just deleting a migration will produce inconsistencies between your actual migrations and what's recorded.
在删除迁移并创建新迁移之前,您需要先通过运行来恢复它。/manage.pymigration my_app number_previous_migration_name
。
Before deleting a migration and creating a new one, you need to first revert it by running ./manage.py migrate my_app number_previous_migration_name
.
这篇关于Django迁移删除和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!