我是flask / Heroku的新手,并使用postgres / sqlalchemy部署应用程序。我正在使用flask-migrate(基于alembic构建)进行数据库迁移。 Everythign在本地工作正常,即使从工头开始,但我无法在Heroku服务器上运行。我相信它与数据库连接和Flask-migrate有关,但我不确定。在这几个小时,并搜索SO无济于事。我知道我犯了一个愚蠢的错误。
安装Heroku Postgres之前出错 -
OperationalError: Could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Heroku Postgres安装后错误 -
2014-05-16T21:26:14.408879+00:00 app[web.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2014-05-16T21:26:14.408880+00:00 app[web.1]: TCP/IP connections on port 5432?
这是我的项目结构
myproject/
-app
-__init__.py
-forms.py
-helper.py
-views.py
-models.py
-static/
-templates/
-config.py
-run.py
-Procfile
-requirements.txt
-migrations/
这是我的 init .py:
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.admin import Admin
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
admin = Admin(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
from app import views, models, forms, helper
这是我的config.py文件:
import os
DEBUG = True
basedir = os.path.abspath(os.path.dirname(__file__))
CSRF_ENABLED = True
CSRF_SESSION_KEY = '**********'
ADMINS = frozenset(['myemail'])
SECRET_KEY = '*******'
if os.environ.get('DATABSE_URL') is None:
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://******@localhost/myproject'
else:
SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']
run.py
#!/usr/bin/env python
from app import manager
manager.run()
Procfile最后但并非最不重要:
web: gunicorn app:app
答案 0 :(得分:3)
选择数据库网址时出现拼写错误:
if os.environ.get('DATABSE_URL') is None:
而不是
if os.environ.get('DATABASE_URL') is None: