jac300
jac300

Reputation: 5222

South 'nothing to migrate' message after successful schema migration

I have a Django app that I added South to, performed some migrations with, and runs as expected on my local machine. However, I have had nothing but database errors after pushing my project to Heroku.

In trying to deal with one database error I am experiencing, I attempted a test where I deleted one of my models, pushed the edited models file to Heroku and ran:

heroku run python manage.py schemamigration django_app test_remove_pub --auto

This seemed to work fine. I got back the message:

Running `python manage.py schemamigration apricot_app test_remove_pub --auto` attached   
to terminal... up, run.6408
 - Deleted model django_app.Publication
 - Deleted M2M table for journalists on django_app.Publication
 - Deleted M2M table for tags on apricot_app.Publication
Created 0006_test_remove_pub.py. You can now apply this migration with: ./manage.py   
migrate django_app

So, South appeared to do everything I expected - it deleted my model and its many to many relationships and made the appropriate migration file. Next, I enter:

 heroku run python manage.py migrate django_app

And I get back:

Running `python manage.py migrate django_app` attached to terminal... up, run.4792  
Running migrations for django_app:
- Nothing to migrate.
- Loading initial data for django_app.
Installed 0 object(s) from 0 fixture(s)

Why would it say "nothing to migrate" when obviously there are things to migrate??

Upvotes: 1

Views: 2814

Answers (1)

karthikr
karthikr

Reputation: 99620

After you change the models, you need to do :

heroku run python manage.py schemamigration django_app --auto

if anything has changed

and then run

heroku run python manage.py migrate django_app

South applies migrations based on the entries in this database table: south_migrationhistory. So if you want to manually override it,

  1. Remove all the entries with column app_name of the models you changed
  2. Manually remove all the related tables. You can get a list of all the tables by typing this in the django shell:

    from django.db.models import get_app, get_models
    app = get_app(app_name)
    for model in get_models(app, include_auto_created=True):
        print model._meta.db_table
    
  3. Remove the migrations/ folder related to the app

  4. Do a fresh migration: ./manage.py schemamigration app_name --initial
  5. Apply the migration ./manage.py migrate app_name

Upvotes: 7

Related Questions