且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?

更新时间:2023-11-18 22:12:22

如果您不想从头开始重新创建模型,可以使用以下 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