﻿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
23474	Schema migrations can inadvertently destroy data	no	nobody	"I attached a sample project that will show that migrations can destroy data.

There are two apps, `A` and `B`, both of which have two migrations. Both of app `B`s migrations depend on `A`'s first migration. Both of app `A`'s migrations are empty noops. Migrating `B` first should apply migrations A.0001, B.0001, B.0002, which will leave the database with the B.B table creating via B.0001.

If you then explicitly migrate A.0001 again, it will unapply B.0001 and B.0002 which removes the B.B table causing data loss. A.0001 should be a noop since it's already been applied. 

Interestingly, this bug only occurs if A.0002 exists.

Here are the steps to reproduce:

{{{#!bash

$ unzip destructive-example.zip
$ cd foo
$ sqlite3 db.sqlite3 "".tables"";
django_migrations
# Create the ""B"" table. Both, b migrations depend on a.0001
$ ./manage.py migrate b
Operations to perform:
  Apply all migrations: b
Running migrations:
  Applying b.0001_initial... OK
  Applying b.0002_b... OK
$ sqlite3 db.sqlite3 "".tables"";
b_b                django_migrations
$ ./manage.py migrate a 0001
Operations to perform:
  Target specific migration: 0001_initial, from a
Running migrations:
  Unapplying b.0002_b... OK
  Unapplying b.0001_initial... OK
$ sqlite3 db.sqlite3 "".tables"";
django_migrations

}}}"	Bug	closed	Migrations	1.7	Release blocker	duplicate		vtiriac@… valtron info+coding@…	Accepted	0	0	0	0	0	0
