将 Django 开发数据库 (.sql3) 迁移到 Heroku

2024-04-03

如何将 Django .sql3 开发数据库迁移到 heroku?

Per here https://stackoverflow.com/questions/14500631/how-can-i-upload-a-db-to-heroku, and here https://stackoverflow.com/questions/20508898/how-can-i-import-a-sql-file-into-my-heroku-postgres-database我试过:heroku pg:psql --app sblic < database.sql3但我的 Django 管理员显示没有新上传(即使在syncdb/migrate/或collectstatic之后)


也许有一种方法可以直接将 sql3 文件上传到 Heroku,但我选择了最明确的路径(将本地 sql3 db 转换为 postgre db 并通过 pg 备份工具将 postgres 数据库转储上传到 Heroku https://devcenter.heroku.com/articles/heroku-postgres-import-export):

  1. 创建 sql3 数据库的转储作为 json 文件 https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql
  2. 安装 PostgreSql 并使用其bin目录中的Path环境变量,创建 postgresql 用户和数据库 http://djangogirls.gitbooks.io/django-girls-tutorial-extensions/content/optional_postgresql_installation/README.html(或者只是计划使用安装 postgresql 时创建的初始超级用户帐户)
  3. 更新您的settings.py with a 引用您新创建的 postgresql 数据库 https://stackoverflow.com/questions/5394331/how-to-setup-postgresql-database-in-django (note, 'HOST'可能需要设置为'localhost', 'user'是您的 postgre 用户登录名)
  4. run python manage.py syncdb启动新的 postgre 数据库
  5. 可选:如果需要,截断你的 postgres 数据库 https://stackoverflow.com/questions/3076928/switching-django-project-from-sqlite3-backend-to-postgresql-failes-when-loading内容类型
  6. 从步骤 1 加载转储 https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql(如果您有固定装置问题,see here https://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django)
  7. 现在你有了一个可用的 postgresql 本地数据库。要迁移,首先创建一个 postgresql 转储 https://devcenter.heroku.com/articles/heroku-postgres-import-export#create-dump-file
  8. 将 postgre 转储发布到可通过 URL 访问的位置(例如上一个链接中建议的投递箱或 amazon s3)。
  9. Perform pgbackups 恢复命令,引用您的转储 url https://devcenter.heroku.com/articles/heroku-postgres-import-export#import-to-heroku-postgres
  10. 您的 heroku 应用程序现在应该引用本地数据库的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Django 开发数据库 (.sql3) 迁移到 Heroku 的相关文章

随机推荐