Well, this error says that you have rows in other(or same) tables referring to this row you are going to delete, and you should delete referring rows first. If you want SQLA to do it automatically, you need to use sessions and mappers (not raw SQL expression engine), more info here:
http://www.sqlalchemy.org/docs/05/ormtutorial.html#configuring-delete-delete-orphan-cascade Regards, Alex On Jan 29, 8:33 am, n00b <pyn...@gmail.com> wrote: > back again, sorry. > > i specified a model with a few one-to-many and one many-to-many > relations using SA 0.51 in MySql 5.1.25 rc; tables are all INNODB. all > works well and as expected in the ORM realm. however, when i'm trying > to use SQL Expression for a delete (row) operation, i get the dreaded > > IntegrityError: (IntegrityError) (1451, 'Cannot delete or update a > parent row: a foreign key constraint fails > > specifically, i'm using: > > engine = create_engine('mysql://root:@localhost:3306/test2') > connection = engine.connect() > metadata = MetaData(bind=engine) > main_table = Table('main_table', metadata, autoload=True) > target_id = 1 #for illustrative purposes, primary key to delete > connection.execute(main_table.delete().where(main_table.c.id > ==target_id)) > > where main_table is my main table and all other tables link to its id > (primary key int) via > foreign keys. > > thx for you help --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---