本文介绍了如何在 Django 1.7 中重置迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我知道有一个与此相同的标题,但问题不同).

(I know there is a title the same as this, but the question is different).

我设法让我的开发机器迁移和生产迁移不同步.

I have managed to get my development machine migrations and production migrations out of sync.

我有一个使用 South 的 Django 应用程序.我有自己的工作流程,运行良好(这可能不是正确的做事方式,但我没有遇到任何问题).

I have a Django app which was using South. I had my own workflow that worked fine (it probably wasn't the correct way to do things, but I had no problems with it).

基本上,我有一个将生产数据库转储复制到我的开发机器的脚本.它还复制了迁移文件.这样两者就同步了,我可以正常运行 South 命令.

Basically I have a script that copies the production database dump to my development machine. It also copied the migration files. That way the two were in synch, and I could run South commands as normal.

现在我已经升级到 1.7,并开始使用迁移.当我使用以前的工作流程(复制数据库转储和从生产中迁移文件)时,它没有检测到我的开发计算机上的更改.

Now I have upgraded to 1.7, and started using migrations. When I use my previous workflow (copy database dump, and migration files from production), it is not detecting changes on my development machine.

我已经通读了迁移文档,我发现正确的使用方法是

I have read through the migrations document, and I see that the correct way to use it is to

  1. 在我的开发机器上运行make migrations"和migrate".
  2. 在我的开发机器上运行迁移"以实际更改数据库
  3. 复制更改,包括迁移文件.
  4. 在生产机器上运行迁移".(没有makemigrations"步骤)

无论如何.现在一切都是一团糟.我想重置"我的迁移并从头开始,从现在开始正确地做事.

Anyway. It is all a mess now. I would like to "reset" my migrations and start from scratch, doing things properly from now on.

我需要做什么?

  1. 删除迁移表的内容(在两台机器上)?
  2. 删除迁移文件夹的内容?(包括 init.py 文件).
  3. 根据新文件的文档开始迁移.

我错过了什么吗?是否有理由从生产中复制所有内容(数据库和迁移文件)之后在我的开发机器上检测不到任何更改

Have I missed anything?Is there a reason why copying everything from production(database and migration files) doesn't detect any changes on my development machine afterwards

推荐答案

我会在两个环境中执行以下操作(只要代码相同)

I would just do the following on both the environments (as long as the code is the same)

  1. 删除您的迁移文件夹
  2. DELETE FROM django_migrations WHERE app = <your app name> .您也可以截断此表.
  3. python manage.py makemigrations
  4. python manage.py migrate --fake
  1. Delete your migrations folder
  2. DELETE FROM django_migrations WHERE app = <your app name> . You could alternatively just truncate this table.
  3. python manage.py makemigrations
  4. python manage.py migrate --fake

在此之后,您的所有更改都应该能够跨环境检测到.

After this all your changes should get detected across environments.

这篇关于如何在 Django 1.7 中重置迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 12:32
查看更多