Migrating an unmigrated database from 1.6 to 1.7

13 views
Skip to first unread message

bobhaugen

unread,
Jul 7, 2016, 7:05:22 AM7/7/16
to Django users
We're upgrading an app from django 1.4 step-by-step through all the versions at least to 1.8. Got a self-inflicted problem with the new migrations in 1.7.

Before we went to 1.7, we added a new field to a model, and migrated the db using South. Then when we went to 1.7, we restarted all the migrations.

Unfortunately, we had one database that did not get the South migration with the new field.

When we merge in the new code with the new field and try a migrate on the unmigrated database, it does nothing. I suppose because all we got now is the new-in-1.7 initial migration.

And of course when I try to run the new code against the unmigrated db, I get an error about the missing field.

I know we did wrong to leave that db unmigrated. But do we have any options for recovery now? Other than dump the data, recreate the db, and reload?

Avraham Serour

unread,
Jul 7, 2016, 8:00:52 AM7/7/16
to django-users
I believe you can checkout your project with a commit still using django 1.6 with south and run the south migration on the remaining database


--
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...@googlegroups.com.
To post to this group, send email to django...@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/3b316785-23c0-4d49-9150-49da28d301ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Ledermann

unread,
Jul 7, 2016, 8:08:51 AM7/7/16
to django...@googlegroups.com
or use

python manage.py sqlmigrate <app_label> <migration_name>

to get the sql, which you than can apply manually
> https://groups.google.com/d/msgid/django-users/CAFWa6tLV2O__terOLDDMm1Eo1XhURjSMKps6nF4Hot7FDVLAYw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Best Regards,

Christian Ledermann

Newark-on-Trent - UK
Mobile : +44 7474997517

https://uk.linkedin.com/in/christianledermann
https://github.com/cleder/


<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>

Remco Gerlich

unread,
Jul 7, 2016, 8:11:09 AM7/7/16
to django...@googlegroups.com
If it's a single database and a single field, is it feasible to just add the field by hand using SQL?

Greetings,
Remco Gerlich

--

bobhaugen

unread,
Jul 7, 2016, 8:28:39 AM7/7/16
to Django users
Thank you all for all your suggestions and your quick responses. I think the 1.6-South idea would work, and likewise adding the field by hand using SQL. 

Problem with sqlmigrate is that all we got now is the initial migration, with all the fields. We don't have a django migration for the new field, that's back in South and 1.6.

In the meantime, I charged ahead with a dump, recreated db, and reloaded the data. Had to comment out the new field temporarily to do the dump. 
I do feel slightly dirty, but have done worse. I think it's ok, but we're doing a bunch of testing.
Reply all
Reply to author
Forward
0 new messages