在水线中将 migrate:safe 设置为用户定义的 table

Set migrate:safe to user defined table in waterline

我必须通过自定义查询方法(.query())在水线中创建用户定义的 table。

custom.con.query("CREATE TABLE "+req.body.table_name+",function(err,model){});

之后,我必须通过自定义查询再次在此 table 中创建列。

custom.con.query("ALTER TABLE "+req.body.table_name+" ADD "+req.body.coloumn_name,function(err,model){});  

问题是一旦 table 创建后它的列也 created.but 当我重新启动服务器时 table 中的列消失了。

在其他水线模型中,我可以通过设置迁移值来解决这个问题:"safe"。

有没有办法在自定义 table 中设置这样的配置???

user786,您的默认 migrate 设置似乎设置为 'alter''drop'。您可以通过将 defaults 对象添加到基线初始化来更改此设置,例如:

var config = {
  // adapters
  // models
  // etc...

  defaults: {
    // will apply to any model that doesn't have a 'migrate' definition
    migrate: 'safe'
  }
};

waterline.initialize(config, function(err, models) {
  console.log("waterline initialised.");
});

waterline examples.

中的代码示例

非破坏性选项是'safe''create',更多细节在adapter specification docs and in sails model settings