I have a website with a number of smaller internal apps. I want to break 
some of them out into reusable apps and I'm starting with a simple one. It 
has a single model and a single initial migration representing it. Very 
simple, no foreign keys etc.

I did this: http://stackoverflow.com/a/8408131 and, as part of that, 
updated django_migrations table to change old app label to new app label. I 
did all these steps in a single RunSQL data migration in my core app which 
is listed first in my APPS settings list:

operations = [
        migrations.RunSQL(
            [("UPDATE django_content_type SET app_label=%s WHERE 
app_label=%s", [NEW_APP, OLD_APP])],
            [("UPDATE django_content_type SET app_label=%s WHERE 
app_label=%s", [OLD_APP, NEW_APP])],
        ),
        migrations.RunSQL(
            "ALTER TABLE " + OLD_APP + "_contact RENAME TO " + NEW_APP + 
"_contact",
            "ALTER TABLE " + NEW_APP + "_contact RENAME TO " + OLD_APP + 
"_contact"
        ),
        migrations.RunSQL(
            [("UPDATE django_migrations SET app=%s WHERE app=%s", [NEW_APP, 
OLD_APP])],
            [("UPDATE django_migrations SET app=%s WHERE app=%s", [OLD_APP, 
NEW_APP])],
        )
    ]

The console output seems to suggest the core migration is indeed running 
before the <new app label> migration tries.

Even though the django_migrations table seems to be updating the app_label 
properly (step 3) the 0001_initial migration in the newly renamed app still 
tries to run. It fails since it's just a create and the table it wants to 
create already exists since the earlier table rename (step 2) made it so.

I guess my general question is on the isolation level of the RunSQL 
migrations. Should I expect the migration for <new app> to see it doesn't 
need to run because django_migrations was updated one step earlier which 
should now say <new app label> has already run 0001_initial?

Doug

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d71d3881-b10d-45a5-9568-54dc59052f19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to