Flask开发中遇到Foreign key associated with column 'users.role_id' could not find table 'rol

Flask开发中遇到Foreign key associated with column 'users.role_id' could not find table 'rol,第1张

概述Flask开发中遇到Foreign key associated with column 'users.role_id' could not find table 'rol

代码:

import osfrom flask_sqlalchemy import sqlAlchemyapp.config['SECRET_KEY'] = 'hard to guess string'app.config['sqlALCHEMY_DATABASE_URI'] =\    "sqlite:///" + os.path.join(basedir, "data.sqlite")app.config['sqlALCHEMY_COMMIT_ON_TEARDOWN'] = Truebasedir = os.path.abspath(os.path.dirname(__name__))db = sqlAlchemy(app)class Role(db.Model):    __tablename__ ="roles"    ID = db.Column(db.Integer, primary_key=True)    name = db.Column(db.String(64),unique=True)    users = db.relationship('User', backref='role')    def __repr__(self):        return "<Role %r>" % self.name        class User(db.Model):    __tablename__ = "users"    ID = db.Column(db.Integer, primary_key=True)    username = db.Column(db.String(64), unique=True, index=True)    role_ID = db.Column(db.Integer, db.ForeignKey("role.ID"))

更改代码:

db.ForeignKey("role.ID")中role少了一个s,且role是不存在这个表role_ID = db.Column(db.Integer, db.ForeignKey("roles.ID"))


总结

以上是内存溢出为你收集整理的Flask开发中遇到Foreign key associated with column 'users.role_id' could not find table 'rol全部内容,希望文章能够帮你解决Flask开发中遇到Foreign key associated with column 'users.role_id' could not find table 'rol所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1198439.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存