我正在使用 Node、Feathers 和 Sequelize 为 SQL Server 2008 数据库设置 API。我已经使用 feathers-sequelize-auto 成功创建了模型和服务,并且大多数路线似乎都在工作。该应用程序运行但出现错误消息:
Unhandled Rejection at: Promise {"_bitField":18087936,"_fulfillmentHandler0":{}}
我收到与其中一个外键相关的路线(/项目)之一错误。/project 的邮递员输出是:
{
"name": "GeneralError",
"message": "Invalid column name 'OrganisationID'.",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
数据库本身一切正常,我可以毫无问题地在相关表上运行查询。
Project.model.js 的相关部分:
字段定义
LeadAgency: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'Organisation',
key: 'OrganisationID'
}
关系:
Project.associate = function(models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
Project.belongsTo(models.Team, { foreignKey: 'TeamID' });
Project.belongsTo(models.Subteam, { foreignKey: 'SubTeamID' });
Project.belongsTo(models.Staff, { foreignKey: 'StaffID' });
Project.belongsTo(models.Organisation, { foreignKey: 'OrganisationID' });
Project.belongsTo(models.Project, { foreignKey: 'ProjectID' });
};
这是 Organisation.model.js 代码:
/* jshint indent: 2 */
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function(app) {
const sequelizeClient = app.get('sequelizeClient');
const Organisation = sequelizeClient.define(
'Organisation',
{
OrganisationID: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
Name: {
type: DataTypes.STRING,
allowNull: false
},
Type: {
type: DataTypes.STRING,
allowNull: true
},
AddressID: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'Address',
key: 'AddressID'
}
}
},
{
tableName: 'Organisation',
timestamps: false
},
{
hooks: {
beforeCount(options) {
options.raw = true;
}
}
}
);
// eslint-disable-next-line no-unused-vars
Organisation.associate = function(models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
Organisation.belongsTo(models.Address, { foreignKey: 'AddressID' });
};
return Organisation;
};
菜鸟在这里,所以可能会遗漏一些明显的东西。帮助表示赞赏!