I have following two schema.
class Stop(Base):
'''
Class Model for Stops
'''
__tablename__ = 'STOPS'
uid = Column('uid', Integer, primary_key=True, autoincrement=False)
category_code = Column('category_code', String(60), nullable=False)
and
class StopName(Base):
'''
Class Model for StopNames
'''
__tablename__ = 'STOP_NAME'
uid = Column('uid', Integer, ForeignKey("STOPS.uid"), primary_key=True)
name = Column('name', String(60), primary_key = True,nullable=False)
lang_code = Column('lang_code', String(4), nullable=False)
stop = relationship("Stop", backref = 'name')
While I try to delete data using the code below from both the tables I get the following error,
session.query(StopName).delete()
session.query(Stop).delete()
New instance <Stop at 0xf593d50> with identity key (<class 'harmonize_station_id.core.model.Stop'>, (400000000,)) conflicts with persistent instance <Stop at 0x3bdd850>
I tried using cascade too, with following
stop = relationship("Stop", backref = 'name',cascade="delete")
I get the following error.
AttributeError: 'StopName' object has no attribute '_sa_instance_state'.