База данных: Mysql с InnoDB
У меня есть 2 таблицы: МАШИНА и СЕМЬЯ. Машина принадлежит семье.
СЕМЬЯ:
#The family of a machine. For exemple, the machine "AMAT 50" belong to the family "AMAT"
class FAMILY(Base):
__tablename__ = 'Family'
id_family = Column(Integer, primary_key = True)
name_family = Column(String(100), nullable=False, unique = True)
machine = relationship('MACHINE', cascade='all,delete', backref='Family')
МАШИНА:
#The machine on which the tests are executed
class MACHINE(Base):
__tablename__ = 'Machine'
id_machine = Column(Integer, primary_key = True)
number_machine = Column(Integer)
id_family = Column(Integer, ForeignKey("Family.id_family"), nullable=False)
__table_args__ = (
UniqueConstraint(number_machine, id_family),
)
Мне бы хотелось, чтобы при удалении семейства машины, связанные с этим семейством, удалялись. Способ, который я показал выше, не работает. Поэтому я также попытался:
FAMILY:
#The family of a machine. For exemple, the machine "AMAT 50" belong to the family "AMAT"
class FAMILY(Base):
__tablename__ = 'Family'
id_family = Column(Integer, primary_key = True)
name_family = Column(String(100), nullable=False, unique = True)
МАШИНА:
#The machine on which the tests are executed
class MACHINE(Base):
__tablename__ = 'Machine'
id_machine = Column(Integer, primary_key = True)
number_machine = Column(Integer)
id_family = Column(Integer, ForeignKey("Family.id_family", ondelete='CASCADE'), nullable=False)
__table_args__ = (
UniqueConstraint(number_machine, id_family),
)
family = db.relationship('FAMILY', backref=backref('Machine', passive_deletes=True))
Но это тоже не сработало.
Спасибо за помощь