如何简化Django 1.7中的迁移? [英] How to simplify migrations in Django 1.7?

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

问题描述

关于South的问题已经存在类似的问题,但是我已经从Django 1.7开始了我的项目,并且没有使用South。

There are already similar questions for South, but I have started my project with Django 1.7 and am not using South.

在开发过程中已经创建了许多迁移,但是该软件尚未发布,并且不存在必须迁移的数据库。因此,我想重置迁移,好像我的当前模型是原始模型一样,然后重新创建所有数据库。

During development a lot of migrations have been created, however the software is not yet delievered and there exists no database that must be migrated. Therefore I would like to reset the migrations as if my current model was the original one and recreate all databases.

推荐的做法是什么?

编辑:自Django 1.8起,有一个名为 squashmigrations 或多或少地解决了此处描述的问题。

As of Django 1.8 there is a new command named squashmigrations which more or less solves the problem described here.

推荐答案

我明白了。我只是想通了,这很好。

I got this. I just figured this out and it is good.


  • 首先,要清除迁移表:

  • First, to clear migrations table:

./manage.py migrate --fake <app-name> zero


  • 删除应用名称/迁移/ 文件夹或内容。

    进行迁移:

    ./manage.py makemigrations <app-name>
    


  • 最后整理您的迁移,而无需进行其他数据库更改:

  • Finally tidy up your migrations without making other database changes:

    ./manage.py migrate --fake <app-name>
    


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

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