[sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
Hi, Much less controversial question this time, I hope ;-) I have: class MyModel(Base) ... I want to do: engine = create_engine(...) engine.execute(DropTable(MyModel.__table__)) engine.execute(CreateTable(MyModel.__table__)) ...of course, this barfs the first time I run it as the table

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Michael Bayer
well the easiest is mytable.drop(engine, checkfirst=True). The check is not within the DropTable construct, which represents just the actual DROP TABLE statement.If you were using DropTable directly you'd call engine.has_table(tablename) first to check for it. On Sep 28, 2011, at 8:07

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
On 28/09/2011 13:19, Michael Bayer wrote: well the easiest is mytable.drop(engine, checkfirst=True). The check is not within the DropTable construct, which represents just the actual DROP TABLE statement.If you were using DropTable directly you'd call engine.has_table(tablename) first to

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Michael Bayer
On Sep 28, 2011, at 8:32 AM, Chris Withers wrote: On 28/09/2011 13:19, Michael Bayer wrote: well the easiest is mytable.drop(engine, checkfirst=True). The check is not within the DropTable construct, which represents just the actual DROP TABLE statement.If you were using DropTable

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Chris Withers
On 28/09/2011 14:09, Michael Bayer wrote: Hmm, but both mysql and postgres (I suspect others do too, but I haven't checked) have DROP TABLE IF EXISTS statements so you don't need to do any checking. That feels like it should be supported by the DropTable construct, what am I missing? oh,

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Michael Bayer
On Sep 28, 2011, at 9:47 AM, Chris Withers wrote: On 28/09/2011 14:09, Michael Bayer wrote: Hmm, but both mysql and postgres (I suspect others do too, but I haven't checked) have DROP TABLE IF EXISTS statements so you don't need to do any checking. That feels like it should be supported by

Re: [sqlalchemy] DropTable if exists

2011-09-28 Thread Mike Conley
On Wed, Sep 28, 2011 at 8:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: On Sep 28, 2011, at 9:47 AM, Chris Withers wrote: On 28/09/2011 14:09, Michael Bayer wrote: I'm doing engine.execute('drop table if exists %s' + table.name) in the meantime, which just feels icky... oh