1

I'm new to Django but I'm deploying a Django-based website to Heroku, using Postgresql. The deployment was successful, and the website is online and has established connection with the database. However, none of the data from my local database has migrated to the heroku database, causing it to be a blank database. If I go into the admin section and manually input a datapoint, it appears on my site, so I know that database is correctly serving data. What is the proper way for migrating data from your local database to your online, heroku version of the database? I thought the following code would migrate the data:

heroku run python manage.py makemigrations
heroku run python manage.py migrate

But apparently I'm missing something.

4
  • Create the migration files locally and push to Heroku. It works, and it's better practice. BTW: this question has been asked here and here. This comment applies to the edited content of the question, not the title or the original stated question. Commented Jan 4, 2019 at 20:48
  • Thank you for pointing those out. Those posts didn't quite have a specific solution, so I asked again. I ended up using fixtures to prepopulate my database, per Robert's suggestion below. Commented Jan 6, 2019 at 3:53
  • By the way, what did you mean by creating the migration files locally and pushing to Heroku? I tried "python manage.py migrate" after making migrations and did a "git push heroku master" but none of the data transferred to my database. I'm assuming by creating the migration files locally, you meant to use fixtures, and what I did aligns with your instructions. Commented Jan 6, 2019 at 4:00
  • Sorry, I misread your question. Since you stated that you ran makemigrations on Heroku, I thought the problem was the automatically generated migration files themselves (which set up the structure of the database). For moving data around, the three options mentioned by Robert H are the best. Commented Jan 6, 2019 at 14:50

1 Answer 1

1

make migrations will create a migration that contains your schema, but no data. The migrate command applies the migration to the database.

In order to provide data to be sent over as part of the migrate command you need to either create a data migration or use a fixture.

Another option you have is to dump your local database and do an import into Heroku Postgres

All in all, it depends on how much local data you have that you want copied over. If its only a few rows, I would use either a data migration or a fixture, if its 100s or 1000s of rows an export/import of your dataset is your best bet.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. I ended up using fixtures to prepopulate my database. So far, it seems to handle my number of rows without problem. Because the data is converted to JSON, and since JSON can be quite stable even with a lot of data, I'm hoping it won't be too much of an issue. And when it does, I'm hoping that I can then break the data into chunks, and load them up as separate fixtures. That's a lot of "I hope," so we will have to see!
No problem, and glad to have helped - if you find this answer has helped you, or resolved your issue please use the up (or down arrows) to indicate helpfulness and the checkmark to accept the answer. Best of luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.