我尝试在我的应用上进行迁移,并且我会遵循此处提供的建议:django 1.7 migrate gets error "table already exists"
具体做法是:
或者,如果您想避免迁移中的某些操作,可以编辑app / migrations目录下的迁移文件,并评论您不希望在迁移执行中执行的操作。
所以现在我的迁移文件是这样的:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('gantt_charts', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Dependency',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', primary_key=True, auto_created=True)),
],
options={
},
bases=(models.Model,),
),
# migrations.CreateModel(
# name='Task',
# fields=[
# ('id', models.AutoField(serialize=False, verbose_name='ID', primary_key=True, auto_created=True)),
# ('title', models.CharField(max_length=100)),
# ('description', models.TextField(blank=True)),
# ('completed', models.BooleanField(default=False)),
# ('project', models.ForeignKey(related_name='tasks', to='gantt_charts.Project')),
# ('subtasks', models.ManyToManyField(blank=True, through='gantt_charts.Dependency', related_name='supertasks', to='gantt_charts.Task', null=True)),
# ],
# options={
# },
# bases=(models.Model,),
# ),
migrations.AddField(
model_name='dependency',
name='subtask',
field=models.ForeignKey(related_name='dependencies_as_subtask', to='gantt_charts.Task'),
preserve_default=True,
),
migrations.AddField(
model_name='dependency',
name='supertask',
field=models.ForeignKey(related_name='dependencies_as_supertask', to='gantt_charts.Task'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='dependency',
unique_together=set([('supertask', 'subtask')]),
),
]
问题是现在迁移工具正在抱怨:
LookupError: App 'gantt_charts' doesn't have a 'task' model.
ValueError: Lookup failed for model referenced by field gantt_charts.Dependency.supertask: gantt_charts.Task
我怀疑是因为桌子存在而导致我的DB / Django崩溃,而Django并不知道。出于某种原因,它没有检查数据库或我的models.py
文件是否存在任务模型。
如何让迁移工作?
FWIW,因为它可能与SQLite相关,并且具有自引用字段(subtasks
)。文档说SQLite可能有错误,这可能是其中一个实例。