【发布时间】:2016-05-06 02:10:30
【问题描述】:
我正在尝试为我的模型创建表,这些表是在我的应用程序的单独模块中定义的。我打电话给db.create_all(),但没有创建表,也没有错误。我已经定义了模型和imported them before calling create_all。为什么这不起作用?
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:123@localhost/flask'
db = SQLAlchemy(app)
from models import User
db.create_all()
db.session.commit()
models.py:
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
__tablename__ = 'users'
uid = db.Column(db.Integer, primary_key = True)
【问题讨论】:
标签: python flask sqlalchemy flask-sqlalchemy