2

I have a Django proyect running in heroku for some time now, the thing is that, tree days ago, I've tryed to update my schema model but, every time I write

heroku run python manage.py migrate quizzer

heroku keeps telling me that everything's up to date, but I've changed my models.py folder and run schema migration as always.

If you know why this is happening or how can I force a schema migration to my heroku app please tell me how.

Ps: I cannot delete the hole database as the data stored in heroku and the data stored in my local server database are not the same, and I don't want to loose the data of my users

Sascuash
  • 3,661
  • 10
  • 46
  • 65
  • Have you applied the schemamigration locally? Are you sure you created a schemamigration and pushed that to heroku? – akhaku Jan 18 '13 at 17:54
  • I'm sure I've applied the schemamigration locally,and pushing it to heroku is the command --> heroku run python manage.py migrate quizzer <-- isn't it? Maybe I'm forgetting something, but I just can't remember what is it if that's the case – Sascuash Jan 18 '13 at 18:02
  • You have to check the migration file into git, and then push that to heroku before you can run the that command. See my answer? – akhaku Jan 18 '13 at 18:03

3 Answers3

5

Here is a workflow for running a schemamigration on quizzer after modifying your models.py

./manage.py schemamigration quizzer --auto # create migration
./manage.py migrate quizzer # apply migration locally
git add .
git commit -m "Changed quizzer models, added schemamigration"
git push heroku
heroku run python manage.py migrate quizzer # apply migration on heroku

It sounds like you might have forgotten to check your migration file (usually found in appname/migrations) into git, commit it and push it to heroku.

akhaku
  • 1,107
  • 7
  • 16
  • How does one run a migration if the code change is going to break site before it is run? Consider the following scenario: A field is added. Code is pushed. Server restarts. Before migration runs, that field is accessed. I think it could be fixed by having two sites operating on the same database? – ustun Jan 18 '13 at 18:13
  • I've just followed your instructions but got Running `python manage.py migrate quizzer` attached to terminal... up, run.6116 Unknown command: 'migrate' Type 'manage.py help' for usage. and in my settings.py I've got INSTALLED_APPS = (..., 'south',..) written, that's why I've no idea why this time isn`t working – Sascuash Jan 18 '13 at 18:16
  • @ustun fair point, the app would probably be crashed in the time between the push and the migration – akhaku Jan 18 '13 at 18:20
  • @ustun unfortunatelly I don't have 2 sites, everytime I've run a migration my server sowed internal server error until the migration took place, but as it was only a minute or so It wasn't a problem, but, if you know any other way please tell me how so I can avoid this problem – Sascuash Jan 18 '13 at 18:21
  • Do you have south in your requirements.txt file? You should have a line that looks like `South==0.7.4`. You can also run `pip freeze > path/to/requirements.txt`. Don't forget to commit the change to it and push it to heroku before running `heroku run manage.py migrate quizzers` – akhaku Jan 18 '13 at 18:24
  • Actually in my requirements.txt I've got South==0.7.5, as I said this is not the first time I upload a new version of the DB, but it's the first time I cannot upload them, sorry for not being able to give you more info, anyway, if you need anything just ask for it and I'll gladly give it to you – Sascuash Jan 18 '13 at 19:35
  • There must be something simple you're missing, are you running this from the right app? Does `heroku run manage.py` show you the south commands? Try running it again? – akhaku Jan 18 '13 at 19:41
  • 1
    @Sascuash The fix is simple, you have to change your workflow, you have to add the migration to your local del, add it to a commit and push only that commit, apply it in heroku and then you can add another commit with the model.py that depends on that migration being done. – Guillermo Siliceo Trueba Jan 19 '13 at 21:02
  • I'm sorry but, what do you mean exactly with local del? If you mean adding using "git add ." and then commit that's something I do to upload code to heroku, anyway, I'll try adding some code and just right after push another upload with just changes in model.py – Sascuash Jan 20 '13 at 22:03
  • By the way, I've just done it and nothing changed, I'm starting to think that it's a problem heroku has – Sascuash Jan 20 '13 at 22:33
  • If you think you could help me, we can use teamviewer or something like that so you can help me solve my problem, I assure you I'll be really grateful to you – Sascuash Jan 20 '13 at 22:35
1

I had this problem too. I solved this by running heroku restart and running the migrate command again. Don't know why it works (suspect it has to do with initial), but at least it works.

Hope that helps!

Vincent van Leeuwen
  • 681
  • 1
  • 9
  • 17
  • I solved this issue so long ago I didn't remember I had it open here. The solution was to migrate backwards, delete the latest migration archive, submit changes, and then migrate again. Hope this can help for the future – Sascuash Feb 27 '14 at 16:01
1

South might be missing from requirements.txt. Try:

pip freeze > requirements.txt

...followed by another git add/commit/push.

Also, according to the South installation instructions, syncdb must be run first, "to make the South migration-tracking tables". So try:

heroku run python manage.py syncdb

...then try the migrate command again.

Francis Potter
  • 1,629
  • 1
  • 17
  • 19