I was wrong, the method emptied the database, but I was checking the tables in the metadata.
This time I am also removing the tables from the metadata, but if i generate the same tables in two separate test methods (with a call to tearDown ans setUp in between), I still get an error about a backref name on a relationship already existing. If I run the same two tests in separate runs the error does not occur and from that i conclude that somehow the metadata retains the class definitions. My tearDown and setUp are: class SQLAtest(unittest.TestCase): def setUp(self): Base.metadata.create_all(engine) self.session = Session() def tearDown(self): self.session.close() tools.drop_tables(Base.metadata, engine, excludes) with tools.drop_tables removing all tables from the database (using the DropEverything function) and all tables except from the excludes from the metadata (with metadata.remove(table) ). Some tables (with class definitions) are defined in modules, while others are generated on the flight (from the class definitions). From the first i just want to remove the records (or regenerate the tables from the existing metadata), while the others i want to remove completely. I have also considered creating new metadata in setUp, but i would not know how to reinitialize it with the classes/tables hard coded in the modules. Is there a way to achieve this or am i missing something? Cheers, Lars On Feb 25, 3:46 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Feb 25, 2012, at 6:57 AM, lars van gemerden wrote: > > > Hi all, > > > I looking for a way to delete/empty a sqlite database completely (can > > be in memory or file). I have tried: > > > - metadata.drop_all(engine); which does not work with cyclic > > references > > The cycles here are only between the ForeignKey objects themselves, in > Python. SQLite doesn't care. Add the use_alter=True flag to each > ForeignKey in a cycle. > > > - solution > > fromhttp://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything; > > it requires names of foreign key columns to be returned by the > > inspector class, however these names are empty > > are you using "PRAGMA foreign_keys = ON" ? I've run this recipe with > that flag on and off and while it doesn't get the foreign key constraints > explicitly, it still drops all the tables just fine. Perhaps I'm not > actually achieving the "foreign_keys=ON" part since SQLite still lets me drop > a table that others are dependent on. -- 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.