开发者

Sqlalchemy & Pylons: Adding new tables to a previously defined database?

开发者 https://www.devze.com 2023-03-18 07:37 出处:网络
Say I create tables in Pylons by running paster setup-app deve开发者_StackOverflow社区lopment.ini

Say I create tables in Pylons by running

paster setup-app deve开发者_StackOverflow社区lopment.ini

It will produce a database file (i.e. mydatabase.db). Now, let's say later I change my model to have more tables and/or columns, how would I ensure that the old data is still preserved and accessible? Do I need to migrate my old database? How does this all work?


As long as you add new tables it should work seamlessly, i.e. it simply creates new tables without touching existing ones. However, if you change existing table schema (e.g. add a new column), you will need to update the DB schema manually or drop/rename that table and run paster setup-app development.ini to recreate it.

Usually I rename the modified table, run setup-app to create a new clean table and copy the data with something like that:

INSERT INTO some_table (col1, col2, col3) SELECT (col1, col2, col3) FROM some_table_old

0

精彩评论

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

关注公众号