7

How does one migrate their Django .sql3 development database to heroku?

django project with important database highlighted that must be migrated

Per here, and here I tried: heroku pg:psql --app sblic < database.sql3 but my Django admin shows no new uploads (even after syncdb/migrate/ or collectstatic

4
  • 1
    Umm: docs.aws.amazon.com/AmazonS3/latest/UG/… Commented Feb 21, 2015 at 19:11
  • The easiest way to move your database and code up to Heroku is just via a git push. Commented Feb 21, 2015 at 20:09
  • Your question shows a SQLite3 database. How is that related to an example that shows how to push a Postgres database? I think you need to re-state your question. Commented Feb 21, 2015 at 20:11
  • @Brandon In Heroku the default database is Postgres, using django on local environment the default is SQLite3. Commented Mar 5, 2017 at 17:00

2 Answers 2

3

Perhaps there may be a way to directly upload an sql3 file to Heroku, but I went with the path of clearest certainty (convert local sql3 db to postgre db and upload a dump of postgre db to Heroku via pgbackups tool):

  1. Create a dump of your sql3 database as a json file
  2. With PostgreSql installed and with its bin directory in the Path environment variable, create a postgre user and database (or just plan on using your initial super user account created upon installing postgresql)
  3. Update your settings.py with a reference to your newly created postgre database (note, 'HOST' may need to be set as 'localhost', 'user' is your postgre user login)
  4. run python manage.py syncdb to initiate your new postgre db
  5. Optional: if necessary, truncate your postgre db of contenttypes
  6. load your dump from step 1 (if you have fixture issues, see here)
  7. Now you have a working postgre local db. To migrate, first create a postgre dump
  8. Post your postgre dump somewhere accessible by URL (such as drop box or amazon s3 as suggested in previous link).
  9. Perform pgbackups restore command, referencing your dump url
  10. Your heroku app should now reference the contents of your local db.
Sign up to request clarification or add additional context in comments.

1 Comment

This always gives fixture error. even after adding arguments like --natural-foreign --natural-primary while dumping. @DanielRoseman sir do you know the fix ? please help.
1

Heroku command line tool uses the psql binary. You have to install PostgreSQL on your local development machine to have psql available. From the (documentation)[https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql]:

You must have PostgreSQL installed on your system to use heroku pg:psql.

You can in fact keep using your SQLite database with Heroku, but this is not recommended as it will be rewritten with your local copy if you re-deploy it to another dyno. Migrating the data to psql is recommended as described at https://devcenter.heroku.com/articles/sqlite3

1 Comment

excellent, but I have a .sql3 database so I'll need to convert to postgres first...

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.