首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用postgresql部署Flask应用程序并获取AttributeError:'drivername‘对象没有’drivername‘属性

使用postgresql部署Flask应用程序并获取AttributeError:'drivername‘对象没有’drivername‘属性
EN

Stack Overflow用户
提问于 2020-07-12 11:29:29
回答 1查看 142关注 0票数 0

当我尝试将我的应用程序部署到Heroku上时,我得到了这个错误日志。

代码语言:javascript
复制
2020-07-12T03:19:13.340263+00:00 app[web.1]:   File "/app/app/__init__.py", line 35, in <module>
2020-07-12T03:19:13.340263+00:00 app[web.1]:     db.Model.metadata.reflect(db.engine)
2020-07-12T03:19:13.340263+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 943, in engine
2020-07-12T03:19:13.340264+00:00 app[web.1]:     return self.get_engine()
2020-07-12T03:19:13.340264+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
2020-07-12T03:19:13.340264+00:00 app[web.1]:     return connector.get_engine()
2020-07-12T03:19:13.340265+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 555, in get_engine
2020-07-12T03:19:13.340265+00:00 app[web.1]:     options = self.get_options(sa_url, echo)
2020-07-12T03:19:13.340265+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 570, in get_options
2020-07-12T03:19:13.340265+00:00 app[web.1]:     self._sa.apply_driver_hacks(self._app, sa_url, options)
2020-07-12T03:19:13.340268+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 883, in apply_driver_hacks
2020-07-12T03:19:13.340268+00:00 app[web.1]:     if sa_url.drivername.startswith('mysql'):
2020-07-12T03:19:13.340269+00:00 app[web.1]: AttributeError: 'NoneType' object has no attribute 'drivername'

这是我的init文件

代码语言:javascript
复制
app = Flask(__name__)

# Ensure responses aren't cached
@app.after_request
def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"
    return response


##where to find the database and initialize SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app) 


##option to tell SQLALchemy that for every model it should just 
#look at the columns that already exist in the table. This is called reflecting
db.Model.metadata.reflect(db.engine)

class Congress(db.Model):
    __tablename__ = 'sen'
    __table_args__ = { 'extend_existing': True }
    id = db.Column(db.Text, primary_key=True) 

过程文件

代码语言:javascript
复制
web: flask db upgrade; gunicorn app:app

我不确定如何补救这种情况,任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2020-07-12 11:39:39

当你在本地运行它的时候,它能工作吗?

问题看起来像是在环境变量DATABASE_URL中,当你部署到heroku时,你是如何声明这个问题的?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62856777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档