Node Feathers Sequelize API无效列名

问题描述 投票:0回答:1

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

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

我收到与其中一个外键相关的路径(/ project)的错误。 / 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;
};

Noob在这里可能会遗漏一些明显的东西。帮助赞赏!

sql-server node.js sequelize.js feathersjs feathers-sequelize
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.