如何在 Sequelize 中使用迁移?
How to use migrations in Sequelize?
我用过EntityFramework, Waterline and Mongoose. I just started using Sequelize. I have created a sample model. Later I wanted to add another column to the table corresponding to the same model. When I edit the model, the new field doesn't seem to be reflecting in the table unless I drop the table. Am I supposed to use Migrations? I got confused after reading the documentation等ORMS。有人可以帮我吗?
是的,您应该像在 sequelize 中编辑模型一样使用迁移,当您的应用程序启动时它只会创建 table 如果它不存在。它不会检查架构是否不同,因此不会更新您的 table.
的架构
如果我是你,我会安装 sequelize-cli
然后 运行 sequelize init
命令。这将使您的项目准备好使用迁移。
请注意,我们使用 sequelize 迁移,您必须显式定义主键、updatedAt 和 createdAt 列,否则它们将无法很好地创建!
关于迁移的文档还不错:http://sequelize.readthedocs.org/en/latest/docs/migrations/
我用过EntityFramework, Waterline and Mongoose. I just started using Sequelize. I have created a sample model. Later I wanted to add another column to the table corresponding to the same model. When I edit the model, the new field doesn't seem to be reflecting in the table unless I drop the table. Am I supposed to use Migrations? I got confused after reading the documentation等ORMS。有人可以帮我吗?
是的,您应该像在 sequelize 中编辑模型一样使用迁移,当您的应用程序启动时它只会创建 table 如果它不存在。它不会检查架构是否不同,因此不会更新您的 table.
的架构如果我是你,我会安装 sequelize-cli
然后 运行 sequelize init
命令。这将使您的项目准备好使用迁移。
请注意,我们使用 sequelize 迁移,您必须显式定义主键、updatedAt 和 createdAt 列,否则它们将无法很好地创建!
关于迁移的文档还不错:http://sequelize.readthedocs.org/en/latest/docs/migrations/