开发者

sqlachemy created mysql table, but I modified table now says 'unknown column url'

开发者 https://www.devze.com 2023-01-09 11:34 出处:网络
I added a url column in my table, and开发者_运维技巧 now sqlalchemy is saying \'unknown column url\'.

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号