在使用babel-node运行sequelize项目,执行create的时候,会报如下错误
TypeError: Class constructor Model cannot be invoked without 'new'
这个问题,找了很久没找到解决方案,暂时的处理方法,就是把es6写法改成define的方式。
比如
class TestUser extends Sequelize.Model{ } TestUser.init({ id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, title: { type: Sequelize.STRING } }, { sequelize: sequelize, modelName: 'test_users', underscored: true, underscoredAll: true });
改成
let TestUser = sequelize.define('TestUser',{ id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, title: { type: Sequelize.STRING } },{ modelName: 'test_users', underscored: true, underscoredAll: true });
这样就可以了