我的本地postgresql数据库URL的形式是什么? [英] What is the form of my local postgresql database url?
问题描述
我正在阅读flask/sqlalchemy教程 https://pythonhosted.org/Flask-SQLAlchemy/quickstart.html#a-minimum-application 并且我将数据库URL配置为:postgres://用户名:密码@localhost:5432/dbname
I am going through a flask/sqlalchemy tutorial https://pythonhosted.org/Flask-SQLAlchemy/quickstart.html#a-minimal-application and I configured my database url to be: postgres://username:password@localhost:5432/dbname
当我在交互式python shell中运行db.create_all()时,它不会引发任何错误,但也不会执行任何操作.
when I run db.create_all() in the interactive python shell it doesn't throw any errors, but it doesn't do anything either.
据我了解,应该创建包含三列的User表;ID,用户名和电子邮件.
From what I understand it is supposed to create the User table with three columns; id, username, and email .
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()
推荐答案
它应该是确切的格式.
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:postgres@localhost/DBNAME"
其中 postgres
是用户名, postgres
是密码, localhost
是地址
Where postgres
is username and postgres
is password, localhost
is address
这篇关于我的本地postgresql数据库URL的形式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!