egg-sequelize插件下使用MSSQL时model报错

Created on 25 Jan 2018  ·  11Comments  ·  Source: eggjs/egg

  • Node Version:V8.9.4
  • Egg Version:2.2.1
  • Plugin Name:egg-sequelize
  • Plugin Version:3.1.0
  • Platform:MacOS
  • Mini Showcase Repository:


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'.

need-more-information egg-sequelize

Most helpful comment

我试试看

All 11 comments

插件有 npm 安装了么?

@atian25 是用cnpm安装的

删除依赖重新安装下看看,不要锁版本。

提供下最小可复现仓库

@atian25 用cnpm重新安装了,问题依旧,求解
仓库:https://github.com/89790094/egg-sequelize-for-mssql-demo

简单看了下, 2 个插件冲突了,去掉 mongoose 就可以。
我印象中 2 个插件是可以共存的,@duncup 帮忙跟下这个?

我试试看

现在两个插件没发共存。

@atian25 刚刚翻了下issues,发现了 #814 。如果想彻底解决这个问题,看起来牵扯到model的重定义了。

@XadillaXhttps://github.com/eggjs/egg/issues/1775 也有关

@atian25 @duncup egg-mongoose和egg-sequelize冲突的问题还在啊,翻了下issues,现在只能略过model,直接在service里写吗?

egg-sequelize 4.x 可以修改加载路径了

Was this page helpful?
0 / 5 - 0 ratings

Related issues

killagu picture killagu  ·  48Comments

fengmk2 picture fengmk2  ·  44Comments

zrxisme picture zrxisme  ·  44Comments

atian25 picture atian25  ·  68Comments

popomore picture popomore  ·  53Comments