﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22476	Migrations fail to migrate m2m fields with custom through model.	Florian Apolloner	Andrew Godwin	"Changing blank and other attributes on a m2m field fails, models:
{{{
from django.db import models


class Table1(models.Model):
    pass

class Table2(models.Model):
    m2m = models.ManyToManyField(Table1, through='M2M')

class M2M(models.Model):
    t1 = models.ForeignKey(Table1, related_name='+')
    t2 = models.ForeignKey(Table2, related_name='+')
}}}

Reproduce by running makemigrations, changing blank to True on the m2m field, rerunning makemigrations and migrate, resulting in:
{{{
Operations to perform:
  Synchronize unmigrated apps: admin, contenttypes, auth, sessions
  Apply all migrations: t1
Synchronizing apps without migrations:
  Creating tables...
    Creating table django_admin_log
    Creating table auth_permission
    Creating table auth_group_permissions
    Creating table auth_group
    Creating table auth_user_groups
    Creating table auth_user_user_permissions
    Creating table auth_user
    Creating table django_content_type
    Creating table django_session
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying t1.0001_initial... OK
  Applying t1.0002_m2m_t2... OK
  Applying t1.0003_auto_20140419_1201...Traceback (most recent call last):
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/home/florian/sources/django.git/django/core/management/__init__.py"", line 427, in execute_from_command_line
    utility.execute()
  File ""/home/florian/sources/django.git/django/core/management/__init__.py"", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/florian/sources/django.git/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/home/florian/sources/django.git/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/home/florian/sources/django.git/django/core/management/commands/migrate.py"", line 145, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File ""/home/florian/sources/django.git/django/db/migrations/executor.py"", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File ""/home/florian/sources/django.git/django/db/migrations/executor.py"", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File ""/home/florian/sources/django.git/django/db/migrations/migration.py"", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File ""/home/florian/sources/django.git/django/db/migrations/operations/fields.py"", line 130, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File ""/home/florian/sources/django.git/django/db/backends/sqlite3/schema.py"", line 151, in alter_field
    new_field,
ValueError: Cannot alter field t1.Table2.m2m into t1.Table2.m2m - they are not compatible types (probably means only one is an M2M with implicit through model)
}}}

Marking as release blocker since this is a bug in a new feature"	Bug	closed	Migrations	dev	Release blocker	fixed	migrations, m2m	Andrew Godwin Florian Apolloner k@…	Accepted	0	0	0	0	0	0
