0

我正在尝试将 Flask 应用程序部署到 Heroku。我已经推送到 Heroku 并且可以访问我的登录页面,但是对 db 的任何调用都会给出 OperationalError:

2014-01-29T12:12:31.801772+00:00 app[web.1]: OperationalError: (OperationalError) no such table: projects_project u'SELECT

使用 Flask-migrate 我可以成功运行本地迁移和升级:

INFO  [alembic.migration] Context impl PostgresqlImpl.
INFO  [alembic.migration] Will assume transactional DDL.
INFO  [alembic.migration] Running upgrade None -> 4b56d58e1d4c, empty message

当我尝试使用升级在 Herokuheroku run python manage.py db upgrade上升级时,似乎发生了,但是 Context impl. 现在是 SQLite?:

(dev01)Toms-MacBook-Pro:dev01 kt$ heroku run python manage.py db upgrade
Running `python manage.py db upgrade` attached to terminal... up, run.9069 
INFO  [alembic.migration] Context impl SQLiteImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.
INFO  [alembic.migration] Running upgrade None -> 4b56d58e1d4c, empty message

运行Heroku pg:info给出:

=== HEROKU_POSTGRESQL_PINK_URL (DATABASE_URL)
Plan:        Dev
Status:      available
Connections: 0
PG Version:  9.3.2
Created:     2014-01-27 18:55 UTC
Data Size:   6.4 MB
Tables:      0
Rows:        0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback:    Unsupported

Heroku 升级的相关日志为:

2014-01-29T12:55:40.112436+00:00 heroku[api]: Starting process with command `python manage.py db upgrade` by kt@gmail.com
2014-01-29T12:55:44.638957+00:00 heroku[run.9069]: Awaiting client
2014-01-29T12:55:44.667692+00:00 heroku[run.9069]: Starting process with command `python manage.py db upgrade`
2014-01-29T12:55:44.836337+00:00 heroku[run.9069]: State changed from starting to up
2014-01-29T12:55:46.643857+00:00 heroku[run.9069]: Process exited with status 0
2014-01-29T12:55:46.656134+00:00 heroku[run.9069]: State changed from up to complete

另外,heroku config给我:

(dev01)Toms-MacBook-Pro:dev01 kt$ heroku config
=== myapp Config Vars
DATABASE_URL:               postgres://xxx.compute-1.amazonaws.com:5432/da0jtkatk6057v
HEROKU_POSTGRESQL_PINK_URL: postgres://xxx.compute-1.amazonaws.com:5432/da0jtkatk6057v

where [xxx == xxx]

上下文实现如何。放?除了在本地工作和 heroku 之间存在明显差异之外,我无法弄清楚发生了什么或应该如何调试。谢谢。

4

1 回答 1

3

数据库的 URL 取自SQLALCHEMY_DATABASE_URIFlask 应用实例中的配置。这发生在文件夹env.py中创建的 Alembic 配置中。migrations

os.environ['DATABASE_URL']在将控制权移交给 Flask-Migrate 和 Alembic 之前,您是否将值存储在配置中?看起来你有一个默认的基于 SQLite 的数据库,它永远不会被 Heroku 提供的真实数据库覆盖。

于 2014-01-29T23:18:39.693 回答