There is a recipe for dropping FK constraints: http://www.sqlalchemy.org/trac/wiki/UsageRecipes
did you find that? In addition, if you wanted to keep the FKs enabled, there is an example here using Metadata.sorted_tables, to get the table list in dependency order. http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html?highlight=sorted_tables#reflecting-all-tables-at-once On Friday, August 17, 2012 4:48:10 AM UTC+2, Greg wrote: > > Hi, > > I was naively trying to clear a db earlier in the day and I ran into this > problem: 'Cannot delete or update a parent row: a foreign key constraint > fails' > > So as anyone would do I've been searching online and through the > documentation on how to turn the foreign keys off, on delete = Cascade, > delete orphan-cascade what have you. So many hours and many stack traces > later I'd like to ask your help in this matter > > def cleanMapping(self, dbName): >> >> connection = self.dbEngines[dbName].connect() >> trans = connection.begin() >> >> for my_table in reversed(self.dbMetaData[dbName].tables.values()): >> keys= my_table.foreign_keys >> for column in my_table.columns: >> for key in keys: >> my_table = Table(my_table, self.dbMetaData[dbName], >> Column(column, Integer, >> ForeignKey(key, onupdate="CASCADE", ondelete = >> "CASCADE") >> ,primary_key=True)) >> connection.execute(my_table.delete()) >> >> trans.commit() > > > So I'm fresh out of ideas; Everytime I try using this code I get > "sqlalchemy.exc.ArgumentError: Column object already assigned to Table > <col>" > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/6EiRPIEPIHAJ. 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.