Reputation: 267010
If I run my python script, it creates the tables correctly.
However, if I add/remove a column and run the script again, it doesn't modify the database.
Why is this?
I am doing this after defining everything:
mapper(Product, products)
mapper(Category, categories)
metadata.create_all(engine)
session = Session()
Upvotes: 0
Views: 1760
Reputation: 16224
create_all only creates. It doesn't modify. http://www.sqlalchemy.org/docs/core/schema.html?highlight=create_all#sqlalchemy.schema.MetaData.create_all
If you've changed the columns you need to either drop/readd the table, or manually add the column outside of your script. There are tools to do this like sqlalchemy-migrate which is a full migrations manager for your project. http://code.google.com/p/sqlalchemy-migrate/
Upvotes: 4
Reputation: 298176
I use SQLAlchemy within Flask, but I think the same concepts apply here. You have to commit the changes when you change something within the database:
session.commit()
Upvotes: 0