Issue
I am creating a CRM system with Django for my non-profit organisation. Have installed a local postgres database to which I created a table students and have added 2 rows via Django Admin interface. When I display these rows in a CSS table by running the app on localhost, the 2 records are correctly displayed.
After migrating and pushing a git commit and then running the Heroku hosted instance of the app. The two records are not visible.
localhost:
Heroku instance:
I have no idea how to push my local updates to the database to the heroku postgres database.
Searched around on the internet and have tried resetting the database but to no avail.
Solution
This is by design.
Most of the data in your database is application state, not code. It's not part of the application, just like the tabs you have open in your browser right now aren't part of the browser application. If I have another copy of that browser running, I'll have a different set of tabs.
Django's database migrations are for migrating your database's structure (schema):
Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema
If you want to copy the data over you've got a few options:
- Manually re-create it, e.g. via the Django admin tool
- Dump your local database and ingest it into your production database, e.g. using
pgdump
andheroku pg:backups:restore
- Dump your Django data to fixtures and load it in Heroku
In general, though, I'd encourage you to think about each application as a separate thing, with its own data. Forcing your production application state to match your local development state is pretty limiting.
Answered By - Chris
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.