sql-server - Node Feathers Sequelize API 无效的列名

标签 sql-server node.js sequelize.js feathersjs feathers-sequelize

我正在使用 Node、Feathers 和 Sequelize 为 SQL Server 2008 数据库设置 API。我已经使用feathers-sequelize-auto 成功创建了模型和服务,并且大多数路线似乎都在工作。该应用程序运行但出现错误消息:

Unhandled Rejection at: Promise  {"_bitField":18087936,"_fulfillmentHandler0":{}}

我收到与其中一个外键相关的路由 (/project) 之一的错误。/project 的 postman 输出是:
{
    "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;
};

这里的菜鸟可能会遗漏一些明显的东西。帮助表示赞赏!

最佳答案

由于model.associate 中的映射不正确,我收到此错误。在您的项目模型中,您也将 Project 定义为关联。这可能是原因。

关于sql-server - Node Feathers Sequelize API 无效的列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51033869/

相关文章:

angularjs - 应在 MEAN 堆栈中的哪个位置创建验证规则?

node.js - GraphQL Apollo 中的多对多关系

javascript - 添加和新列/属性以 Sequelize 模型

sql-server - 如何从 VBA 中的函数返回 ADODB.Connection?

c# - SSMS 中的 SQL 查询有效但在 C# 中无效

sql - 在 SQL 中分隔地址字符串

sql - 如何使用外键选择用户集合?

sql - 将关系数据从数据库复制到数据库

mysql - 使用nodejs在Mysql查询中传递数组

javascript - 如何延迟 pm2 下集群进程的 "online"事件?