本文介绍了南迁移:删除所有迁移文件(00 * _ *),并从0001开始,同时保留原始数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用Django开发Web系统,并且部署在Heroku上。系统生产后,必须保留所有数据库数据和迁移文件(即00 * _ *文件)。以下是我执行数据库迁移和部署的过程: 对于第一个部署,执行 manage .py makemigrations 本地推送到Heroku。 执行 manage.py migrate 如果型号稍后更改: 在本地执行 makemigrations ,然后推送到Heroku。 在Heroku上执行迁移 如果模型更改,步骤3和4将重复。 随着系统的发展,迁移文件越来越多。我想知道:成功迁移和部署后,我可以删除所有的迁移文件,并开始像新的一样吗?那就是: 对于第一次部署,请在本地执行 makemigration 在Heroku上执行迁移 删除所有本地迁移文件。 在本地执行 makemigrations 似乎启动迁移文件。 更改型号: 在本地执行 makemigration 并推送到Heroku。 在Heroku上执行迁移 如果模型更改,步骤3到6将重复。 上述步骤是否正确?解决方案对于您的每个应用程序: 1)假装回滚所有现有的迁移: ./ manage.py migrate app zero --fake 零参数表示我们回滚到第一次迁移。您可以通过运行 ./ manage.py migrate app --list 确认所有迁移都已回滚。 - 假的选项信号我们不应该实际运行迁移,但仍将迁移标记为已运行: https://docs.djangoproject.com/en/1.8/ref/django -admin /#django-admin-option --- fake 2)。删除迁移文件 git rm app / migrations / * 3)创建新的迁移文件 ./ manage.py makemigrations app 4)假装运行新的迁移 ./ manage.py migrate app --fake 如在1),步骤4)实际上并没有运行迁移。 编辑:添加了一些解释,并修正了零参数。 I am developing web systems using Django and they are deployed on Heroku. After the system goes production, all database data and the migration files (i.e., the 00*_* files) have to be retained. The followings are my procedure to perform database migration and deployment:For the first deployment, perform manage.py makemigrations locally and push to Heroku.Perform manage.py migrate on Heroku.If models are changed later:Perform makemigrations locally and push to Heroku.Perform migrate on Heroku.Steps 3 and 4 are repeated if models are changed.As the system evolves, there are more and more migration files. I am wondering: after a successful migration and deployment, can I just delete all migration files and start like a fresh one? That is:For the first deployment, perform makemigration locally and push to Heroku.Perform migrate on Heroku.Delete all local migration files.Perform makemigrations locally to create seemingly start-up migration files.Change models:Perform makemigration locally and push to Heroku.Perform migrate on Heroku.Steps 3 to 6 are repeated if models are changed.Is the above procedure correct? 解决方案 For each of your app:1) Pretend to rollback all existing migrations:./manage.py migrate app zero --fakeThe zero argument indicates that we rollback to the first migration. You can confirm all migrations have been rollbacked by running ./manage.py migrate app --list.The --fake option signals we should not actually run the migrations, but nonetheless mark the migrations as having been run: https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake2). Delete migration filesgit rm app/migrations/*3) Create a new migration file./manage.py makemigrations app4) Pretend to run the new migration./manage.py migrate app --fakeAs in 1), step 4) does not actually run the migrations.EDIT: added some explanations and fixed the zero argument. 这篇关于南迁移:删除所有迁移文件(00 * _ *),并从0001开始,同时保留原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 00:50