On Jun 17, 4:00 am, Francisco Souza <[email protected]> wrote: > > But do I do this? Part of the problem is that I don't know of a way > > to generate tables other than create_all() (or drop_all()) when using > > declarative syntax. Is there another way? > > Hi Shane :) > > When you bind your declarative base to a metadata, the "metadata" object has > a attribute called "tables", wich is a dict with all tables containeds in > this metadata. So, you can do a create for a single table easily. > > >>> Base.metadata.tables['test_case'].create(engine) > > You can call it on your upgrade function inside the migration module.
Isn't this incredibly problematic if you need to change the model definition later? What if you need to add a column to this table in a new migration later on? It will work on your existing databases, but if you run through your migrations on a fresh database, you'll have a problem because the first migration created the table with the extra column in place, and the second migration won't be able to add the column again. The sqlalchemy-migrate docs suggest you copy and paste Table definitions to avoid this behavior (ugh). But when you're using DeclarativeBase you don't even have any Table definitions to copy from! Is there any way around this other than not running migrations when creating new databases (and instead sticking with create_all() directly)? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en.
