-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't create record with composite primary key #405
Comments
Up |
Hi @garcia-marco, Can you provide more details about your issue. Looking at the failure log Let us know. |
Hi, I'm sorry I forgot to answer at the time.
It wasn't working if there was an existing row with one of the primary_key like :
I fixed it by setting only one primary key "id" that I added at the time This was my model at the time: module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
const Table = sequelize.define('table', {
first_id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
second_id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
third_id: {
type: DataTypes.INTEGER,
primaryKey: true,
defaultValue: 1,
}
}, {
tableName: 'table',
underscored: true,
underscoredAll: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at'
});
Table.removeAttribute('id');
Table.associate = (models) => {
Table.belongsTo(models.first, {
foreignKey: 'first_id'
})
Table.belongsTo(models.second, {
foreignKey: 'second_id'
})
Table.belongsTo(models.third, {
foreignKey: 'third_id'
})
};
return Table;
}; |
Hello
Expected behavior
Create or edit a record in a table with 3 primary keys.
Actual behavior
It doesn't create or edit a record
Failure Logs
*TABLE NAME* creation failed: PRIMARY must be unique
Context
I'm on my local environment.
The text was updated successfully, but these errors were encountered: