
您需要将约束添加到表,而不是模型。为此,请使用声明式:
class EventInvitation(db.Model): # ... __table_args__ = ( db.UniqueConstraint(event_id, from_id, to_id), )
如果已经在数据库中创建了表,则需要删除该表并
db.create_all()再次运行,或者使用Alembic通过迁移来更改现有表。
欢迎分享,转载请注明来源:内存溢出

您需要将约束添加到表,而不是模型。为此,请使用声明式:
class EventInvitation(db.Model): # ... __table_args__ = ( db.UniqueConstraint(event_id, from_id, to_id), )
如果已经在数据库中创建了表,则需要删除该表并
db.create_all()再次运行,或者使用Alembic通过迁移来更改现有表。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)