Configuration: TG2, MySQL, SQLAlchemy
The tg_user_group table uses onupdate='CASCADE', ondelete='CASCADE',
and it is functional (when I delete a user, the associated entry in
tg_user_group is deleted.
However, when I use ondelete='CASCADE' from within a DeclarativeBase
class as follows:
class ABC(DeclarativeBase):
__tablename__ = 'abc'
id = Column(Integer, autoincrement=True, primary_key=True)
created = Column(DateTime, default=datetime.now)
class XYZ(DeclarativeBase):
__tablename__ = 'xyz'
id = Column(Integer, autoincrement=True, primary_key=True)
abc = Column(ForeignKey('abc.id', onupdate='CASCADE',
ondelete='CASCADE'))
When a row in ABC table is deleted (via application), the associated
row (ForeignKey) in XYZ table is not deleted, instead it has the 'abc'
column set to NULL.
The documentation @
http://www.sqlalchemy.org/docs/core/schema.html#on-update-and-on-delete
states the following:
Note that these clauses are not supported on SQLite, and require
InnoDB tables when
used with MySQL. They may also not be supported on other
databases.
I do not setup any special config in MySQL nor in TG2 regarding
InnoDB.
Question 1: Why does the ondelete='CASCADE' seem to work for the
external tg_user_group (M-to-M relation), whereas it does not work for
the above scenario, in the same application.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.