我是
python的新手.我必须使用Postgresql作为数据库开发一个简单的Flask应用程序(在我的本地Ubuntu 16.4中).
我安装了pgadmin,Flask,sqlAlchemy和postgres,这也是我的应用代码:
from flask import Flask from flask_sqlalchemy import sqlAlchemy app = Flask(__name__) app.config['sqlALCHEMY_DATABASE_URI'] = 'postgresql://dbUserName:userNamePassword@localhost/dbname' db = sqlAlchemy(app) class User(db.Model): id = db.Column(db.Integer,primary_key=True) username = db.Column(db.String(80),unique=True) email = db.Column(db.String(120),unique=True) def __init__(self,username,email): self.username = username self.email = email def __repr__(self): return '<User %r>' % self.username @app.route('/') def index(): return "Hello Flask" if __name__ == "__main__": app.run()
我还在pgAdmin中创建了一个数据库和@R_502_6284@(并在我的代码中用相关变量替换它们),但是当我尝试在python shell中测试这段代码时,我发现错误.
我的python代码:
from app import db
结果:
/home/user/point2map2/venv/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:839: FSADeprecationWarning: sqlALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 'sqlALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
然后:
db.create_all()
结果:
(psycopg2.OperationalError) FATAL: password authentication Failed for user "dbUserName" FATAL: password authentication Failed for user "dbUserName"
经过大量的论坛搜索,我找到了这个指南:
in your pg_hba.conf
06005
但它不适合我.
我遇到了同样的错误.
对我来说问题是我没有为psql用户设置密码.
在这里看到类似的问题和答案:
https://askubuntu.com/questions/413585/postgres-password-authentication-fails
对我来说问题是我没有为psql用户设置密码.
在这里看到类似的问题和答案:
https://askubuntu.com/questions/413585/postgres-password-authentication-fails
我这样做就解决了
ALTER USER db_username PASSWORD 'new_password'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。