当我试图通过Sequelize从NODEJS中的某条路线获取数据时,我得到的是未知列的错误,既不是模型也不是下面的路由是我的代码 .
我的模特
module.exports = function(sequelize, DataTypes) {
return sequelize.define('ProspectType', {
ProspectTypeID: {
type: DataTypes.INTEGER(11),
allowNull: false
},
ProspectTypeName: {
type: DataTypes.STRING(50),
allowNull: true
}
}, {
tableName: 'ProspectType'
});
};
我的路线
.get('/prospectType', function (req, res) {
models
.ProspectType
.findAll()
.then(function (data) {
res
.json(data);
})
.catch(function (error) {
res
.boom
.notAcceptable(error);
});
})
即使没有列'id'我也会收到此错误
SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field
list'
1 回答
我假设您希望
ProspectTypeID
成为主键 . 但是你没有告诉续集这是你的主键 . 因此,如果正在寻找id
的默认主键 .只需将其声明为模型中的主键即可,您应该很好