Migrating database from local development to Heroku-Django 1.8

时间:2015-06-25 18:26:30

标签: python django postgresql heroku django-database

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 个答案:

答案 0 :(得分:17)

如果数据库很小并且你觉得这很幸运,那么

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

答案 1 :(得分:9)

我也有这个错误,我的解决方案有点不同。问题与使用的格式有关。转储数据库时我需要使用--format = c。

为了解决这个问题,我使用--format = c

再次转储数据库
pg_dump --no-acl --no-owner --format=c database_name > db.dump

然后将其导入我的heroku应用

heroku pg:backups restore 'url_for_db.dump' DATABASE_URL

希望这可以帮助将来的某个人!

答案 2 :(得分:1)

您可以使用: heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi

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

答案 3 :(得分:1)

对于Windows用户;

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

根据官方文档,如果您使用的是Windows,请务必在远程网址周围使用双引号。 see official docs

相关问题