如何重置Django 1.7中的迁移 [英] How to reset migrations in Django 1.7

查看:146
本文介绍了如何重置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.

我有一个使用南方的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).

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

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.

我已经阅读了迁移文档,我看到正确的使用方法是在我的开发机器上运行make migration和migrate来

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

    / li>
  1. 在我的devlopemnt机器上运行迁移实际使数据库更改

  2. 复制更改,包括迁移文件。

  3. 在生产机器上运行迁移。 (没有makemigrations步骤)

  1. run "make migrations" and "migrate" on my development machine.
  2. run "migrate" on my devlopemnt machine to actually make the database changes
  3. Copy changes over, including migration files.
  4. run "migrate" on the production machine. (without the "makemigrations" step)

无论如何。现在都是一团糟我想重新设置我的迁移,从头开始,从现在开始正常运行。

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. 根据新的文档开始迁移。

  1. Delete the contents of the migration table (on both machines)?
  2. Delete the contents of the migration folder? (Including the init.py file).
  3. Start the migrations as per the documentation for a new one.

我错过了什么?
是否有原因从生产(数据库和迁移文件)复制一切都不会在我的开发机器上检测到任何更改

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 = <你的应用程序名称> 。您可以另行截取此表。

  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中的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆