#23474: Schema migrations can inadvertently destroy data
-------------------------------+--------------------
     Reporter:  Naddiseo       |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Migrations     |    Version:  1.7
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 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

 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23474>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.8b078fbcf3980cc8b2726e10091c7667%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to