gpt4 book ai didi

postgresql - 属性错误 : 'ParseResult' object has no attribute 'drivername'

转载 作者:行者123 更新时间:2023-11-29 13:54:41 25 4
gpt4 key购买 nike

我在 Heroku 上运行应用程序时遇到问题。本地版本似乎工作正常,但我无法在 heroku 平台上调用 create_db()

这是错误轨迹。

(venv)S-MBP:LaunchPage3 S$ heroku run python
Running python on herokuapp... up, run.5609
Python 2.7.11 (default, Dec 7 2015, 21:16:24)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from app import db
>>> db.create_all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 910, in get_engine
return connector.get_engine()
File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 542, in get_engine
self._sa.apply_driver_hacks(self._app, info, options)
File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 846, in apply_driver_hacks
if info.drivername.startswith('mysql'):
AttributeError: 'ParseResult' object has no attribute 'drivername'

这是app.py

import os, requests, json
from flask import Flask, render_template, request, redirect
import psycopg2, urlparse
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

if 'PRODUCTION' in os.environ:
urlparse.uses_netloc.append("postgres")
app.config['SQLALCHEMY_DATABASE_URI'] = urlparse.urlparse(os.environ["DATABASE_URL"])
else:
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:root@localhost:5432/db'
app.config['SQLALCHEMY_ECHO'] = True

db = SQLAlchemy(app)

[CODE - ONE FILE APPLICATION WITH DB MODELS ETC]

if __name__ == '__main__':
db.create_all()
port = int(os.environ.get('PORT',5000))

if 'PRODUCTION' in os.environ:
app.debug = False
app.run(host='0.0.0.0', port=port)
else:
app.debug = True
app.run(host='127.0.0.1', port=port)

任何指针将不胜感激。我尝试关注 other question在 SO 但这些答案没有帮助。

最佳答案

尝试将 import urlparse 更改为:

from urlparse import urlparse

关于postgresql - 属性错误 : 'ParseResult' object has no attribute 'drivername' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34462738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com