I'm trying to make migrations on my app, and I'be followed the advice supplied here: django 1.7 migrate gets error "table already exists"
Specifically:
Or if you want to avoid some actions in your migration, you can edit the migration file under the app/migrations directory and comment the operations you don't want to do in the migrate execution.
So now my migration file looks like so:
# -*- 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')]),
),
]
The issue is now the migration tools is complaining:
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
My suspicion is that some how I've broken my DB/Django by having the table exist, and Django not know about it. For some reason it's not checking the DB or my models.py
file for the existance of the task model.
How can I get the migration to work?
FWIW, and because it might be relevant I'm on SQLite and have a self-referential field (subtasks
). The docs say that SQLite can be buggy and this might be one of those instances.