In a live web app, I have the following models (abridged):
class Ad(models.Model):
name = models.CharField(max_length=50)
apps = models.ManyToManyField(App, null=True, blank=True)
class App(models.Model):
name = models.CharField(max_length=50)
I have the following tables (in my staging environment):
sqlite> .tables
auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_flatpage
django_flatpage_sites
django_migrations
django_session
django_site
myapp_app
myapp_ad
I no longer want Ad
to have a ManyToMany relation to App
, so I removed apps
from Ad
.
Then, I ran:
env/bin/python manage.py makemigrations
It produced this migration:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('myapp', '0035_auto_20150818_1302'),
]
operations = [
migrations.RemoveField(
model_name='ad',
name='apps',
),
]
Then, I ran:
env/bin/python manage.py migrate
The migration fails with the following error:
django.db.utils.OperationalError: no such table: myapp_ad_apps
I imagine that this is because I'm doing something wrong with the behind-the-scenes many to many table created for me when I first used the ManyToMany field. How can I alter my migration so that it succeeds?