How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
问题描述
我有一组 Sequelize 模型.我想使用迁移,而不是数据库同步.
I have a set of Sequelize models. I want to use migrations, not DB Sync.
Sequelize CLI 似乎能够做到这一点,根据 这篇文章:当您使用 CLI 生成模型时,您还将免费获得迁移脚本."
Sequelize CLI seems to be able to do this, according to this article: "When you use the CLI for the model generation, you will gain the migration scripts for free as well."
如何使用 Sequelize CLI 从现有的 Sequelize 模型自动生成迁移?
How to auto generate the migrations with Sequelize CLI from existing Sequelize models?
推荐答案
如果您不想从头开始重新创建模型,可以使用以下 CLI 命令手动生成迁移文件:
If you don't want to recreate your model from scratch, you can manually generate a migration file using the following CLI command:
sequelize migration:generate --name [name_of_your_migration]
这将生成一个空白的骨架迁移文件.虽然它不会将您的模型结构复制到文件中,但我确实发现它比重新生成所有内容更容易、更干净.注意:确保从迁移目录的包含目录运行命令;否则 CLI 会为你生成一个新的迁移目录
This will generate a blank skeleton migration file. While it doesn't copy your model structure over to the file, I do find it easier and cleaner than regenerating everything. Note: make sure to run the command from the containing directory of your migrations directory; otherwise the CLI will generate a new migration dir for you
这篇关于如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01