停止sails.js中模式的自动迁移

Stop the auto migration of the schema in the sails.js

本文关键字:迁移 模式 sails js 停止      更新时间:2024-06-21

在sails.js中,我们如何停止将模式自动迁移到数据库中。有时,它会由于迁移而出错。有没有一种方法可以让迁移只在部署应用程序时运行?

您也可以尝试以下操作:

module.exports = {
  // migrate: 'alter', // adds and/or removes columns on changes to the schema 
  // migrate: 'drop', // drops all your tables and then re-creates them. All data is deleted.
  // migrate: 'safe', doesn't do anything on sails lift- for use in production.
  attributes: { /* ... */ }
};

我们可以通过在模型中指定migrate属性来实现这一点。它的默认值是alter,它尝试在每次更改时自动迁移模式。

module.exports = {
  schema: true,
  migrate: 'safe',
  adapter: 'mysql',
  attributes: {}
}

对于所有可以在confing/models.js 中更改的模型

migrate: 'safe',