炼金术与炼金术Pylons:向先前定义的数据库添加新表?
假设我通过运行在 Pylons 中创建表
paster setup-app development.ini
它将生成一个数据库文件(即 mydatabase.db)。现在,假设稍后我将模型更改为具有更多表和/或列,我将如何确保旧数据仍然保留并可访问?我需要迁移旧数据库吗?这一切是如何运作的?
Say I create tables in Pylons by running
paster setup-app development.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要添加新表,它就应该无缝工作,即它只是创建新表而不触及现有表。但是,如果您更改现有表架构(例如添加新列),则需要手动更新数据库架构或删除/重命名该表并运行
paster setup-appdevelopment.ini
来重新创建它。通常我会重命名修改后的表,运行 setup-app 创建一个新的干净表并使用类似的内容复制数据:
INSERT INTO some_table (col1, col2, col3) SELECT (col1, col2, col3) FROM some_table_old< /代码>
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