我有两张表,News
和Files
# unrelated columns removed
class News(db.Model):
id = db.Column(db.Integer, primary_key=True)
file_id_logo = db.Column(db.Integer, db.ForeignKey('files.id'))
logo = db.relationship('File', lazy=False)
class File(db.Model):
id = db.Column(db.Integer, primary_key=True)
news_id = db.Column(db.Integer, db.ForeignKey('news.id'))
news = db.relationship('News', lazy=False, backref=db.backref('files'))
在添加file_id_logo
fkey之后,SQLalchemy引发了一个CircularDependencyError。我已经在logo
关系中尝试了post_update=True
,但是它没有改变任何东西。
解决这个问题的正确方法是什么?
以下情况是可能的(以防万一):
news
.如果新闻有logo
,则引用的文件也会将此新闻作为其徽标
发布于 2011-05-01 02:59:02
use_alter -传递给底层ForeignKeyConstraint以指示应从CREATE TABLE/ DROP TABLE语句外部生成/删除约束。有关详细信息,请参阅该类的构造函数。
https://stackoverflow.com/questions/5843704
复制相似问题