我的代码在本地工作,但是当我尝试在 Heroku 上运行它时它不起作用。我在 Heroku 上添加了一个数据库,但它仍然无法工作。为什么会发生这种情况的任何线索?
import sys
import os
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
db_local = #it works, just not shown here
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', db_local)
app.secret_key = ' ' #it's a secret for a reason
db = SQLAlchemy(app)
from views import *
from model import *
db.create_all()
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)
我的一些heroku日志
2013-02-19T22:29:59+00:00 app[web.1]: File "app.py", line 23, in <module>
2013-02-19T22:29:59+00:00 app[web.1]: from views import *
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/views.py", line 1, in <module>
2013-02-19T22:29:59+00:00 app[web.1]: from app import db
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/app.py", line 25, in <module>
2013-02-19T22:29:59+00:00 app[web.1]: db.create_all()
2013-02-19T22:29:59+00:00 app[web.1]: self._execute_for_all_tables(app, bind, 'create_all')
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy.py", line 822, in create_all
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy.py", line 814, in _execute_for_all_tables
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2564, in create_all
2013-02-19T22:29:59+00:00 app[web.1]: import utils
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/utils.py", line 1, in <module>
2013-02-19T22:29:59+00:00 app[web.1]: Traceback (most recent call last):
2013-02-19T22:29:59+00:00 app[web.1]: conn = self.contextual_connect(close_with_result=False)
2013-02-19T22:29:59+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2490, in contextual_connect
2013-02-19T22:29:59+00:00 app[web.1]: self.pool.connect(),
2013-02-19T22:29:59+00:00 app[web.1]: tables=tables)
2013-02-19T22:29:59+00:00 app[web.1]: con = self._create_connection()