﻿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
22359	Changing m2m field to blank=True makes failed migration on sqlite	Stephen Burrows	nobody	"If I change a M2M field by adding blank=True, the migration that django creates fails on SQLite. Specifically, it tries to re-create the M2M table (even though it already exists.)

I find this especially strange since adding blank=True to an M2M field actually doesn't change the database structure at all.

Migration file:

{{{
# encoding: utf8
from django.db import models, migrations


class Migration(migrations.Migration):

    dependencies = [
        ('brambling', '0021_auto_20140330_1917'),
    ]

    operations = [
        migrations.AlterField(
            model_name='person',
            name='event_types',
            field=models.ManyToManyField(to='brambling.EventType', blank=True),
        ),
        migrations.AlterField(
            model_name='person',
            name='dance_styles',
            field=models.ManyToManyField(to='brambling.DanceStyle', blank=True),
        ),
    ]

}}}

Traceback:

{{{
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "".../django/django/core/management/__init__.py"", line 427, in execute_from_command_line
    utility.execute()
  File "".../django/django/core/management/__init__.py"", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "".../django/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "".../django/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File "".../django/django/core/management/commands/migrate.py"", line 145, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File "".../django/django/db/migrations/executor.py"", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "".../django/django/db/migrations/executor.py"", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "".../django/django/db/migrations/migration.py"", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "".../django/django/db/migrations/operations/fields.py"", line 130, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "".../django/django/db/backends/sqlite3/schema.py"", line 143, in alter_field
    return self._alter_many_to_many(model, old_field, new_field, strict)
  File "".../django/django/db/backends/sqlite3/schema.py"", line 168, in _alter_many_to_many
    self.create_model(new_field.rel.through)
  File "".../django/django/db/backends/schema.py"", line 253, in create_model
    self.execute(sql, params)
  File "".../django/django/db/backends/schema.py"", line 95, in execute
    cursor.execute(sql, params)
  File "".../django/django/db/backends/utils.py"", line 77, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "".../django/django/db/backends/utils.py"", line 61, in execute
    return self.cursor.execute(sql, params)
  File "".../django/django/db/utils.py"", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "".../django/django/db/backends/utils.py"", line 61, in execute
    return self.cursor.execute(sql, params)
  File "".../django/django/db/backends/sqlite3/base.py"", line 479, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table ""brambling_person_event_types"" already exists
}}}"	Bug	closed	Migrations	1.7-beta-1	Release blocker	fixed		Stephen Burrows adrien loic@…	Accepted	1	0	0	0	0	0
