Home Django Heroku and postgresql
Reply: 2

Django Heroku and postgresql

SumNeuron Published in 2017-09-13 13:43:00Z

I am new to publishing django apps on heroku. I have read their tutorials and figured I would start simple by modifying their template django project.

So far everything was good.

Then I made an app as one does, made a model and ran

python3 manage.py makemigrations my_app
python3 manage.py migrate

and things seemed ok.

I then pushed to heroku and there were no immediate complaints.

However, now when I try to make save a new model I get the error:

ProgrammingError at /my_app/
relation "my_app_myappmodel" does not exist
LINE 1: INSERT INTO "my_app_myappmodel" ("field1", "field2", "field3") VALUES...


So I run this locally and everything works fine.

I have tried cleaning my migrations, faking my migrations, squashing my migrations, etc (as other S.O. posts suggest)

Nothing works.

What is up and how do I fix it?

Daniel Roseman
Daniel Roseman Reply to 2017-09-13 14:01:15Z

You need to actually run the migrations on Heroku once you have pushed the code generated by makemigrations. You do this via heroku run manage.py migrate.

Tushortz Reply to 2017-09-13 14:11:50Z

run the following command from your terminal

heroku run python manage.py migrate

or you can also do:

in your local settings.py, change your DATABASES variable to use the heroku one then run from the terminal

python manage.py makemigrations
python manage.py migrate

but you should not normally locally make changes to the heroku production database (as in option 2) except if you are really desperate or don't care

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299189 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO