Flask 迁移错误 - 与列关联的外键找不到 table 用于生成目标列的外键
Flask migrate error - foreign key associated with column could not find table with which to generate a foreign key to target column
我在不同的文件中有如下两个模型。当我 运行 flask db migrate 我得到这个错误。
raise exc.NoReferencedTableError(
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'datasets.user_id' could not find table 'user' with which to generate a foreign key to target column 'id'
我做错了什么?请帮帮我,谢谢。
class User(Model):
__tablename__ = "users"
id = Column(db.Integer, primary_key=True)
email = Column(db.String(64), unique=True, index=True)
username = Column(db.String(15), unique=True, index=True)
role_id = Column(db.Integer, db.ForeignKey("roles.id"))
userdataset = db.relationship("Dataset", backref="user")
class Dataset(db.Model):
__tablename__ = 'datasets'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
如果将数据集table中的外键值设置为users.id,就可以了。
我在不同的文件中有如下两个模型。当我 运行 flask db migrate 我得到这个错误。
raise exc.NoReferencedTableError(
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'datasets.user_id' could not find table 'user' with which to generate a foreign key to target column 'id'
我做错了什么?请帮帮我,谢谢。
class User(Model):
__tablename__ = "users"
id = Column(db.Integer, primary_key=True)
email = Column(db.String(64), unique=True, index=True)
username = Column(db.String(15), unique=True, index=True)
role_id = Column(db.Integer, db.ForeignKey("roles.id"))
userdataset = db.relationship("Dataset", backref="user")
class Dataset(db.Model):
__tablename__ = 'datasets'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
如果将数据集table中的外键值设置为users.id,就可以了。