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?
2条答案
按热度按时间vi4fp9gy1#
Hope the following link will be helpful for you. It asks to put
IF NOT EXISTS
to the SQL script as follows,Check this link. It is the same question that you have asked
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.