views:

21

answers:

2

I added a url column in my table, and now sqlalchemy is saying 'unknown column url'.

Why isn't it updating the table?

There must be a setting when I create the session?

I am doing:

Session = sessionmaker(bind=engine)

Is there something I am missing?

I want it to update any table that doesn't have a property that I added to my Table structure in my python code.

+1  A: 

I'm not sure SQLAlchemy supports schema migration that well (atleast the last time I touched it, it wasn't there).

A couple of options.

  1. Don't manually specify your tables. Use the autoload feature to have SQLAlchemy automatically read out the columns from your database. This will require tests to make sure that it works but you get the idea in generally. DRY.
  2. Try SQLAlchemy migrate.
  3. Manually update the table after you change the model specification.
Noufal Ibrahim
+1  A: 

In cases when you just add new columns, you can safely use metadata.create_all(bind=engine) to update your schema from your class definitions.

However this will NOT modify existing columns or remove columns from DB schema if you remove them in SQLA definition.

Daniel Kluev