Ven*_*esh 2 node.js sequelize.js
当我尝试通过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'
});
};
Run Code Online (Sandbox Code Playgroud)
我的路线
.get('/prospectType', function (req, res) {
models
.ProspectType
.findAll()
.then(function (data) {
res
.json(data);
})
.catch(function (error) {
res
.boom
.notAcceptable(error);
});
})
Run Code Online (Sandbox Code Playgroud)
即使没有列“ id”,我也会收到此错误
SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field
list'
Run Code Online (Sandbox Code Playgroud)
我假设您想ProspectTypeID成为主键。但是,您尚未告诉续集这是您的主键。因此,如果要查找默认主键为id。
只需在模型中将其声明为主键,就可以了
ProspectTypeID: {
type: Sequelize.STRING(50),
allowNull: false,
primaryKey: true,
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3898 次 |
| 最近记录: |