django 1.7迁移 - 如何清除所有迁移并从头开始? [英] django 1.7 migrations -- how do I clear all migrations and start over from scratch?
问题描述
所以我现在正在快速迭代一个django应用程序,我不断调整models.py。在一两天的编程和测试过程中,我生成了几十个迁移文件。有时我真的把模式分开,完全重新做。这导致迁移过程对默认值和空值等提出很大的抱怨。如果可能的话,我只想抓住所有的迁移资料,重新启动迁移,我终于知道我在做什么了。我的方法到目前为止是:
So I'm rapidly iterating on a django app at the moment and I'm constantly adjusting models.py. Over the course of a day or two of programming and testing I generate a couple dozen migration files. Sometimes I really tear the schema apart and completely re-do it. This causes the migration process to complain a great deal about defaults and null values and so on. If possible, I would just like to scratch all the migration stuff and re-start the migrations now that I finally know what I'm doing. My approach thus far has been the following:
- 删除迁移文件夹中的所有内容,除了
__ init __。py
。
- 放入我的PostgreSQL控制台,然后执行以下操作:
DELETE FROM south_migrationhistory WHERE app_name ='my_app';
li>
- 在PostgreSQL控制台中,删除与my_app关联的所有表。
- 重新运行
./ manage.py makemigrations my_app
- 这会在我的迁移文件夹中生成一个0001_initial.py
文件。 - 运行
./管理迁移my_app
- 我希望这个命令重新构建所有的表,而是说:没有迁移应用。
- delete everything in the migrations folder except for
__init__.py
. - drop into my PostgreSQL console and do:
DELETE FROM south_migrationhistory WHERE app_name='my_app';
- while at the PostgreSQL console, drop all of the tables associated with my_app.
- re-run
./manage.py makemigrations my_app
- this generates a0001_initial.py
file in my migrations folder. - run
./manage migrate my_app
- I expect this command to re-build all my tables, but instead it says: "No migrations to apply."
什么给了?
另外,是 south_migrationhistory
数据库表仍然在玩,现在我已经倾销了南方,并已经切换到Django 1.7?
Also, is the south_migrationhistory
database table still in play now that I've dumped South and have switched to Django 1.7?
谢谢。
推荐答案
所以我在q中概述了一步一步的计划uestion确实有效,但不是从 south_migrationhistory
数据库表中删除行,而是必须从 django_migrations
数据库中删除行表
So the step-by-step plan I outlined in my question does work, but instead of deleting rows from the south_migrationhistory
database table, I had to delete rows from the django_migrations
database table.
命令是: DELETE FROM django_migrations WHERE app ='my_app'
一旦完成,您将能够从头开始重新运行迁移。
Once this is done, you will be able to re-run your migrations from scratch.
这篇关于django 1.7迁移 - 如何清除所有迁移并从头开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!