Repository navigation
Closed
Labels
existing workaroundFor issues. There is a known workaround for this issue.type: bugDEPRECATED: replace with the "bug" issue type
Description
Issue Description
What are you doing?
//So here is my Sequelize model, which is a join table between the tables shows and tags (I commented out the associations to make sure that the issue is not with associations):
module.exports = (sequelize, DataTypes) => {
const ShowsTag = sequelize.define('ShowsTag', {
showId: {
type: DataTypes.BIGINT,
allowNull: false,
field: 'show_id'
},
tagId: {
type: DataTypes.BIGINT,
allowNull: false,
field: 'tag_id'
},
tagConnectType: {
type: DataTypes.STRING,
allowNull: true,
field: 'tag_connect_type'
}
}, {
tableName: 'shows_tags',
timestamps: true,
underscored: true
});
ShowsTag.associate = function(models) {
// associations can be defined here
//models.ShowsTag.belongsTo(models.Tag, {as: 'tag'});
//models.ShowsTag.belongsTo(models.Show, {as: 'show'});
};
return ShowsTag;
};
//Here is the code where I am creating a new record:
db.ShowsTag.create({showId: 3, tagId: 3, tagConnectType: 'channel'}).then(d =>
console.log(d)
)What do you expect to happen?
It should insert with showId = 3 and tagId = 3.
What is actually happening?
It's sending to database, showId = null and tagId = null.
_The output was: (Note that show_id is equivalent to showId, as it is an underscored model)
Executing (default): INSERT INTO "shows_tags" ("show_id","tag_id","tag_connect_type","created_at","updated_at") VALUES (NULL,NULL,'channel','2019-09-08 21:51:33.930 +06:00','2019-09-08 21:51:33.930 +06:00') RETURNING *;
Unhandled rejection SequelizeDatabaseError: null value in column "show_id" violates not-null constraint
Additional context
Add any other context or screenshots about the feature request here.
Environment
- Sequelize version: [email protected] -> [email protected] ->[email protected]
- Node.js version: v10.16.2
- Operating System: MacOS Mojave - 10.14.6 (18G95)
- If TypeScript related: N/A
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect. (I am using Postgres)
Would you be willing to resolve this issue by submitting a Pull Request?
- No, I don't have the time and I wouldn't even know how to start.
Reacted by Pedro Augusto de Paula Barbosa, Maxime Daffis, Robert Marriott, Tyler Biscoe, Meruzh Kiloyan, Andre Carvalho, Gabriel Shomorin and Firman Fhaya
Metadata
Metadata
Assignees
Labels
existing workaroundFor issues. There is a known workaround for this issue.type: bugDEPRECATED: replace with the "bug" issue type
Activity
bclark-systech commentedon Sep 17, 2019
Having the same problem. I did find a workaround by passing in the fields option. Not sure if this is a bug or a feature.
malko42 commentedon Oct 16, 2019
I have the same issue with
Sequelize 4.44.3
Node 12.4.0
OS Arch linux 5.3.6
And strangely enough for a
Tagsmodel too.I can confirm the workaround works.
gon-escalante commentedon Dec 26, 2019
adding the primaryKey attribute to one of the fields in model solved this issue for me, there seems to be a problem with the underscored fields
papb commentedon Jan 16, 2020
Closing in favor of #11225
normandanielmq commentedon Nov 8, 2022
When i faced this issue, there was a misconfiguration between the tables. Take a look at how they are related in the models.
ephys commentedon Nov 8, 2022
Can you open a new issue with the information the template will request and a SSCCE/MVCE?
fhyfr commentedon Feb 18, 2023
tovaru commentedon Jun 23, 2023
I had this issue because I was using super many-to-many, where I defined both hasMany and belongsToMany between tables.
I solved it by changing the order in which I define relations; by setting belongsToMany before hasMany.
egmontaska commentedon Jul 13, 2023
Had this issue in many-to-many relation while models having property
underscored: true. Resolved by adding foreignKey property to association definition.Before:
After: