问题描述
我正在尝试重命名django网站中的应用程序之一.还有另一个依赖于它及其mysql表的应用程序.我遍历了两个应用程序中的所有文件,并将旧名称的实例更改为新名称.
I'm trying to rename one of the apps in my django website. There is another app which depends on it and its mysql tables. I went over all the files in both apps and changed the instances of the old name to the new one.
但是,现在我在尝试执行迁移时遇到此错误消息:
However, now I encounter this error message when trying to perform a migration:
File "/Users/Limor/anaconda/lib/python2.7/site-packages/Django-1.10a1-py2.7.egg/django/db/migrations/loader.py", line 287,
in check_consistent_history
migration[0], migration[1], parent[0], parent[1],
django.db.migrations.exceptions.InconsistentMigrationHistory:
Migration manual_tasks.0001_initial is applied before its dependency beta.0001_initial
我找不到解决此问题的方法,如果我尝试注释掉引发异常的特定功能,则会遇到相关问题.我注定要失败,还是有办法解决?
I couldn't find a solution for this issue, and if I tried to comment out the particular function which raises the exception I run into related issues down the road. Am I doomed, or is there a way to fix it?
谢谢!
旧名称是version_1,新名称是beta,依赖它的另一个应用程序是manual_tasks.
the old name is version_1, the new is beta and the other app which relies on it is manual_tasks.
这是代码的结构:
~/website/
|-- .ebextensions
| `-- django.config
|-- project
| |-- __init__.py
| |-- local_settings.py
| |-- settings.py
| |-- urls.py
| `-- wsgi.py
|-- db.sqlite3
|-- manage.py
|--beta
| |-- __init__.py
| |-- admin.py
| |-- apps.py
| |-- local_settings.py
| |-- models.py
| |-- tests.py
| |-- urls.py
| |-- views.py
| |-- migrations
| |-- __init__.py
| |-- 0001__initial.py
| |-- static
| |-- assets
| |-- images
| |-- templates
|--manual_tasks
| |-- __init__.py
| |-- admin.py
| |-- apps.py
| |-- models.py
| |-- tests.py
| |-- urls.py
| |-- views.py
| |-- migrations
| |-- __init__.py
| |-- 0001__initial.py
| |-- static
| |-- assets
| |-- images
| |-- templates
`-- requirements.txt
希望这更有意义!
推荐答案
我认为您在将应用程序重命名为 beta 之前已经运行了名为 version_1.0001_initial 的迁移.您所需要做的就是更新表 django_migrations 中的数据库记录,并使用以下SQL语句将旧的应用程序迁移重命名为新名称:
I think you already run migration named version_1.0001_initial before you renamed app to beta. All you need is to update database records in the table django_migrations and rename old app migrations to the new name using this SQL statement:
UPDATE django_migrations SET app = 'beta' WHERE app = 'version_1';
这篇关于更改Django应用名称时的迁移历史记录不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!