Python 我的本地postgresql数据库url的形式是什么?
我正在学习烧瓶/炼金术教程 我将我的数据库url配置为: postgres://username:password@localhost:5432/dbname 在交互式python shell中运行db.create_all()时,它不会抛出任何错误,但也不会执行任何操作 据我所知,它应该创建包含三列的用户表;id、用户名和电子邮件Python 我的本地postgresql数据库url的形式是什么?,python,postgresql,flask,sqlalchemy,Python,Postgresql,Flask,Sqlalchemy,我正在学习烧瓶/炼金术教程 我将我的数据库url配置为: postgres://username:password@localhost:5432/dbname 在交互式python shell中运行db.create_all()时,它不会抛出任何错误,但也不会执行任何操作 据我所知,它应该创建包含三列的用户表;id、用户名和电子邮件 from flask import Flask, url_for, render_template from flask.ext.sqlalchemy impor
from flask import Flask, url_for, render_template
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://username:password@localhost:5432/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.debug = True
@app.route("/")
def hello():
return render_template('hello.html')
if __name__ == "__main__":
app.run()
从烧瓶导入烧瓶,url\u为,呈现\u模板
从flask.ext.sqlalchemy导入sqlalchemy
app=烧瓶(名称)
app.config['SQLALCHEMY\u DATABASE\u URI']='postgres://username:password@localhost:5432/dbname'
db=SQLAlchemy(应用程序)
类用户(db.Model):
id=db.Column(db.Integer,主键=True)
username=db.Column(db.String(80),unique=True)
email=db.Column(db.String(120),unique=True)
定义初始化(自我、用户名、电子邮件):
self.username=用户名
self.email=电子邮件
定义报告(自我):
返回“%self.username”
app.debug=True
@附件路线(“/”)
def hello():
返回render_模板('hello.html')
如果名称=“\uuuuu main\uuuuuuuu”:
app.run()
尝试在URL中使用postgresql
,而不是postgres
这是JDBC和SQLAlchemy文档()中使用的表单。它应该是精确的格式
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:postgres@localhost/DBNAME"
其中,
postgres
是用户名,postgres
是密码,localhost
是地址是的,我试过了,但随后我进入psql控制台检查是否创建了任何新表,没有看到任何内容。嗯。。。因此,您可以通过psql连接这些相同的参数。。。postgres日志里有什么吗?需要检查一下。我在mac os上使用postgres.app,不确定这是否会有什么不同。刚刚找到这个链接啊。是的,看起来默认情况下没有启用链接日志记录。我在Ubuntu上使用Postgres,通常是从源代码编译的,所以我对Postgres.app不太熟悉。基本上,它似乎是一个带有一些附加组件的Postgres的盒装版本。您使用的是哪个驱动程序?驱动程序。@SpencerCooley你能发布你的psql
查询吗,在那之前你做过create\u db()