当我在模型中定义一个唯一的列时,我正在使用带有sequelize的GraphJS:
const Product = Connection.define('Product', {
label: {
type: Sequelize.STRING,
allowNull: false,
unique: true <--------------
},
description: {
type: Sequelize.TEXT,
allowNull: false
},
price: {
type: Sequelize.FLOAT(6, 3),
}
});
当我尝试插入 第二行时,使用相同的标签:
const Mutations = new GraphQLObjectType({
name: 'Mutations',
description: 'All Mutations',
fields: () => {
return {
addProduct: {
type: Product,
args: {
new: {
name: 'New product',
type: ProductInput
}
},
resolve(_, args) {
return Db.models.Product.create(args.new);
}
},
};
}
});
我收到以下错误:
TypeError: Cannot read property '2' of null
有什么想法吗?
答案 0 :(得分:0)
你似乎不是唯一一个遇到这个问题的人:
https://github.com/sequelize/sequelize/issues/6725
https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/71
你也使用mysql,如果是哪个版本?
似乎在某些版本中有效,而在某些版本中则不行:
https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/71#issuecomment-255192417