Django migration delete and update

余生长醉 提交于 2020-07-23 11:31:07

问题


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

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

This generate migrationB. I was hoping this can do the same as squashing migration files.

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/57417233/django-migration-delete-and-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!