检查以下我一直在使用的代码。我遇到的问题是我的SQLAlchemy缺少模型:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost/flask-movie'
db = SQLAlchemy(app)
class User(db.model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
def __init__(self, username, email):
self.username = username
self.email = email
def __repr__(self):
return '<User %r>' % self.username
答案 0 :(得分:5)
你的班级定义应该以大写字母开头model
,如下所示:
class User(db.Model):
# ...