我在DB (mysql)中使用表和视图,所以对于dev/test环境,我想使用sync(),但是它会在视图上崩溃。
我能略去这些模型吗?
发布于 2019-06-18 08:39:28
我刚做了:
const MyView = sequelize.define('myView', {
ids: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
},
volumeSum: {
type: DataTypes.INTEGER
}
});
// To avoid table creation
MyView.sync = () => Promise.resolve();
然后sequelize.sync();
没有为视图创建表。希望能帮上忙..。
发布于 2017-02-11 05:53:09
不能通过在主续集中使用同步来跳过模型,
但是,您可以使用模型同步函数,并且只能在您想要同步的模型上调用同步函数。
http://docs.sequelizejs.com/en/latest/api/model/#sync-promisethis
发布于 2017-02-13 10:59:27
好的,正如告诉Keval我需要在模型上同步(),所以我从sequelize.sync()复制/粘贴代码并修改它:
if (config.sync && config.sync != 'false') {
let models = [];
sequelize.modelManager.forEachModel(function(model) {
if (model && model.options.sync !== false) {
models.push(model);
} else {
// DB should throw an SQL error if referencing inexistant table
}
});
return Sequelize.Promise.each(models, function(model) {
return model.sync(config.sync);
});
}
https://stackoverflow.com/questions/42159779
复制相似问题