Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Heroku Error "Your models have changes that are not yet reflected in a migration"

I recently added a model to my app (UserProfile) and when I pushed the changes to Heroku, I think I accidentally ran heroku run python manage.py makemigrations. Now when I try to run heroku run python manage.py migrate I get the error below

(leaguemaster) benjamins-mbp-2:leaguemaster Ben$ heroku run python manage.py migrate
Running `python manage.py migrate` attached to terminal... up, run.1357
Operations to perform:
  Synchronize unmigrated apps: allauth
  Apply all migrations: auth, admin, socialaccount, sites, accounts, account, contenttypes, sessions, leagueapp
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

How do I fix this? Please help!

like image 830
Ben Avatar asked Feb 19 '15 04:02

Ben


2 Answers

You need to first create the migrations locally, add them to your repository, commit the files with the new migrations and then push to heroku.

The sequence is something like this:

1. (add/modify some someapp/models.py)
2. python manage.py makemigrations someapp
3. python manage.py migrate
4. git add someapp/migrations/*.py (to add the new migration file)
5. git commit -m "added migration for app someapp"
6. git push heroku
7. heroku run python manage.py migrate
like image 123
Burhan Khalid Avatar answered Nov 20 '22 02:11

Burhan Khalid


1. Make migrations locally

$ python manage.py makemigrations && python manage.py migrate

2. Commit changes and push it on the server

$ git add --all
$ git commit -m "Fixed migrate error"
$ git push heroku master

3. Now run migrate on the server

$ heroku run python manage.py migrate

You also need to be sure that you haven't ignored these migration paths in your .gitingnore file

like image 9
Ged Flod Avatar answered Nov 20 '22 02:11

Ged Flod