SQL Server Sequelize Error : Column names in each table must be unique

rbl8hiat  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(163)

I had an error in Sequelize with a foreign key not matching a column name. Checking the DB, I saw that the column 'WokflowId' was named 'WorkflowID', so I changed the name in the Sequelize model.

It looks like this

'use strict';
const Sequelize = require('sequelize');
const sequelize = require('../util/database');

const WorkflowsAccessRights = sequelize.define('Workflows_AccessRights', {  
  id:{
    type: Sequelize.BIGINT,
    autoIncrement: true,
    allowNull: false,
    primaryKey: true
  },
  WorkflowID: Sequelize.BIGINT,
  GroupID: Sequelize.BIGINT,
  Enabled: Sequelize.INTEGER
},{
  timestamps: false,
  freezeTableName: true,
});

module.exports = WorkflowsAccessRights

But now that I changed the column name to get the right one, I get this error

Column names in each table must be unique. Column name 'WorkflowId' in table 'Workflows_AccessRights' is specified more than once.

Except that, no column has this name now... Did I miss something in the setup or is there a way to freeze the column name?

vi4fp9gy

vi4fp9gy1#

Hope the following link will be helpful for you. It asks to put IF NOT EXISTS to the SQL script as follows,

IF NOT EXISTS(SELECT * FROM sys.columns WHERE Name = 'ColumnName' 
              AND object_id = OBJECT_ID('YourTableName'))
BEGIN
   ALTER TABLE dbo.YourTableName
      ADD ColumnName INT    -- or whatever it is
END

Check this link. It is the same question that you have asked

lzfw57am

lzfw57am2#

So, after searching in the whole project. I found out that I was calling a foreignKey on WorkflowId. Therefore Sequelize tried to create a new column called WorkfklowId and had a bug doing it. I just renamed the foreignKey and it worked.

相关问题