我正在尝试在父(Product)和子表(ProductVariant)之间设置删除级联,但它无法正常工作。我做错了什么?
from sqlalchemy.orm import relationship, backref
Base = declarative_base()
class Product(Base):
__tablename__ = 'product'
id = Column(Integer, primary_key=True)
title = Column(String)
collection_id = Column(Integer, ForeignKey('collection.id'))
class ProductVariant(Base):
__tablename__ = 'product_variant'
id = Column(Integer, primary_key=True)
title = Column(String)
product_id = Column(Integer, ForeignKey(Product.id, ondelete='CASCADE'), nullable=False)
product = relationship(Product, backref= backref("variants", cascade='delete'))