[Answered ]-Update Django app hosted at pythonanywhere

2đź‘Ť

do you mean you’ve made changes to the database on your local PC (new or modified models.py) and you want to know how to apply them to the existing database on PythonAnywhere without breaking existing data?

It depends what version of django you’re using. For versions 1.6 and older, you would use a tool called south. For more recent versions, 1.7 and onwards, you would use the built-in migrations framework.

If you’re using django-migrations, then it should be very simple and “just work”. Pull down your latest code onto PythonAnywhere, activate your virtualenv, and then run

python manage.py migrate 

If you need to use South, it’s a little more complicated. You’ll have to do something like this:

  1. go back to a commit that matches the code that’s currently live on pythonanywhere
  2. for each of your apps, run python manage.py schemamigration appname --initial
  3. now check out the latest version of your code
  4. for each of your apps, run python manage.py schemamigration appname --auto
  5. commit the new migrations files into your repository
  6. pull down the latest code on PythonAnywhere
  7. for each of your apps, run python manage.py mygrate appname --fake 001
  8. then run python manage.py migrate

More info in the south docs. This is quite tricky stuff so backup your database first!

But hopefully you’re using a modern version of django, and you can do it the easy way 🙂

👤hwjp

Leave a comment