config/config.default.js
module.exports = appInfo => {
return {
keys:'*******',
sequelize: {
dialect: 'mssql',
database: 'dataName',
host: '127.0.0.1',
port: '1433',
username: 'uname',
password: 'userpwd'
}
}
}
config/plugin.js
module.exports = {
sequelize:{
enable: true,
package: 'egg-sequelize',
},
}
app/model/jianyi.js
'use strict';
module.exports = app => {
console.log(app.Sequelize);//输出undefined
const { STRING, INTEGER, DATE} = app.Sequelize;
const Jiangyi = app.model.define('jiangyi', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
kemu: INTEGER
});
return Jiangyi;
};
error:TypeError: Cannot destructure property STRING of 'undefined' or 'null'.
插件有 npm 安装了么?
@atian25 是用cnpm安装的
删除依赖重新安装下看看,不要锁版本。
提供下最小可复现仓库
@atian25 用cnpm重新安装了,问题依旧,求解
仓库:https://github.com/89790094/egg-sequelize-for-mssql-demo
简单看了下, 2 个插件冲突了,去掉 mongoose 就可以。
我印象中 2 个插件是可以共存的,@duncup 帮忙跟下这个?
我试试看
现在两个插件没发共存。
@atian25 刚刚翻了下issues,发现了 #814 。如果想彻底解决这个问题,看起来牵扯到model的重定义了。
跟 @XadillaX 的 https://github.com/eggjs/egg/issues/1775 也有关
@atian25 @duncup egg-mongoose和egg-sequelize冲突的问题还在啊,翻了下issues,现在只能略过model,直接在service里写吗?
egg-sequelize 4.x 可以修改加载路径了
Most helpful comment
我试试看