Heroku上的Alembic / Flask-migrate迁移运行但不创建表

时间:2014-01-29 13:29:32

标签: postgresql heroku flask alembic flask-migrate

我正在尝试将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

当我尝试使用heroku run python manage.py db upgrade升级Heroku时,升级似乎会发生,但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之间的明显区别,我无法弄清楚正在发生的事情或我应该如何调试。感谢。

1 个答案:

答案 0 :(得分:3)

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

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