【发布时间】:2021-07-19 04:35:45
【问题描述】:
我在 Heroku 上部署了一个 Django 应用程序。 我正在尝试使用 Heroku Postgres 插件将数据库从 mySQL 切换到 Postgres
我删除了所有迁移并运行 manage.py makemigrations 以获得干净的迁移日志。 然后我提交并推送。
如果我在本地机器上运行 manage.py migrate,我会得到: “经理”的迁移:
manager/migrations/0001_initial.py
- Create model AbiMapping
- Create model MissingContracts
- Create model TempEmailAccounts
- Create model UnsupportedMetaContracts
- Create model Users
- Create model Passwords
- Create model ContractMapping
- Create model Tokens
我将此命令添加到 Procfile,以便在我推送到 Heroku 时运行迁移:
release: python3 manage.py migrate
当推送到 Heroku 时,迁移调用有效,但它不会迁移我在应用中拥有的模型:
remote: Verifying deploy... done.
remote: Running release command...
remote:
remote: Operations to perform:
remote: Apply all migrations: admin, auth, contenttypes, manager, sessions
remote: Running migrations:
remote: No migrations to apply.
这就是我设置数据库的方式 settings.py:
.env 在本地机器上设置环境变量。在 heroku 数据库上,环境变量是从环境中加载的,因为没有 .env
dotenv_file = os.path.join(BASE_DIR, ".env")
if os.path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
设置数据库:
DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
django_on_heroku.settings(locals())
似乎数据库确实存在于heroku中:
$ heroku config
=== frame-zero Config Vars
DATABASE_URL: postgres://<details of my database address and credentials>
谢谢
【问题讨论】:
标签: django postgresql heroku django-models django-migrations