我想在flask-sqlalchemy中定义一个从两个基本模型继承的模型,如下所示:
class BaseModel(db.Model):
id = db.Column(db.Integer(). primary_key=1)
class BaseModelA(BaseModel):
base_model_a_field = db.Column(db.String(9))
base_model_a_type = db.Column(db.String(9))
__mapper_args__ = {"polymorphic_identity": "a", "polymorphic_on": base_model_a_type}
class BaseModelB(BaseModel):
base_model_b_field = db.Column(db.String(9))
base_model_b_type = db.Column(db.String(9))
__mapper_args__ = {"polymorphic_identity": "b", "polymorphic_on": base_model_b_type}
class InheritancedModel(BaseModelA, BaseModelB):
model_a_id = db.Column(db.Integer(), db.ForeignKey("base_model_a.id"), primary_key=1)
model_b_id = db.Column(db.Integer(), db.ForeignKey("base_model_b.id"), primary_key=1)
other_field = db.Column(db.String(9))
创建InheritancedModel
的实例时,
IntegrityError: (_mysql_exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails
发生了。
我可以在sqlalchemy中对连接表继承进行多重继承吗?
我在sqlalchemy中找不到有关多重继承的任何信息。