Migrating database from local development to Heroku-Django 1.8

2.8k Views Asked by At

After establishing a database using heroku addons:create heroku-postgresql:hobby-dev, I tried to migrate my local database to heroku database. So I first ran

heroku python manage.py migrate. After that I created a dump file of my local database using pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump. I uploaded my mydb.dump file to dropbox and then used the following command to load the dump to my heroku database

 heroku pg:backups restore'https://www.dropbox.com/s/xkc8jhav70hgqfd/mydb.dump?' HEROKU_POSTGRESQL_COLOR_URL

But, that throws the following error -

 r004 ---restore---> HEROKU_POSTGRESQL_PURPLE
 [0KRunning... 0.00B..
 [0KAn error occurred and your backup did not finish.
 Please run `heroku pg:backups info r004` for details.

And on running heroku pg:backups info r004 I get -

Database:    BACKUP
Started:     2015-06-25 18:19:37 +0000
Finished:    2015-06-25 18:19:38 +0000
Status:      Failed
Type:        Manual
Backup Size: 0.00B
=== Backup Logs
2015-06-25 18:19:38 +0000: waiting for restore to complete
2015-06-25 18:19:38 +0000: pg_restore: [archiver] did not find magic string in file header
2015-06-25 18:19:38 +0000: restore done
2015-06-25 18:19:38 +0000: waiting for download to complete
2015-06-25 18:19:38 +0000: download done

There is not much information on this error online and I can't figure out what the problem is.

4

There are 4 best solutions below

3
On BEST ANSWER

If the database is small and you feel lucky this might do it

pg_dump --no-acl --no-owner -h localhost -U myuser myd | heroku pg:psql
0
On

For windows users;

heroku pg:backups:restore "https://s3.amazonaws.com/me/items/3H0q/mydb.dump" DATABASE_URL

According to the official docs, be sure to use double-quotes around the remote url if you're using windows. see official docs

2
On

I've had this error too and my solution was a little different. The problem was related to the format used. I needed to use --format=c when dumping the db.

To solve it I dumped the db again using --format=c

pg_dump --no-acl --no-owner --format=c database_name > db.dump

Then importing it to my heroku app

heroku pg:backups restore 'url_for_db.dump' DATABASE_URL

Hope this helps someone in the future!

0
On

You can use : heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi

source: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push