Model.update() set null on values which are not given
See original GitHub issueFor me this is a bug. Let’s say I have a table ‘users’ with 4 columns: ‘firstName’, ‘lastName’, ‘createdAt’, ‘updatedAt’. I do:
User.update({ firstName: 'Jane' }, { where: { id: 1 } })
The SQL query looks like this:
UPDATE "users" SET "first_name"="Jane","last_name"=NULL,"created_at"=NULL,"updated_at"=NULL WHERE "id" = '1'
Why other values are set to NULL ? I think the correct update should look like this:
UPDATE "users" SET "first_name"="Jane" WHERE "id" = '1'
I can’t imagine situation when I would like on update null-ify other values.
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
How to .update() value to NULL in sequelize - Stack Overflow
My model does allowNull which I believe is what allows null values to be the default as well as set: testCol: { type:...
Read more >SQL Server: Foreign Keys with set null on delete
It means that the child data is set to NULL when the parent data is deleted or updated. SET DEFAULT. It is used...
Read more >Update Model from database does not update Nullable Property
i.e. When I change a column in the database from NOT NULL to NULL and then run the Update wizard, I see the...
Read more >How to Replace Nulls with 0s in SQL - The Data School
Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and...
Read more >Working with SQL NULL values - SQLShack
In terms of the relational database model, a NULL value indicates an ... The AVG () is used to calculate the average value...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Workaround is to set the
fields
option on the update function toObject.keys(req.body)
, worked for me, at least.@sw-yx that’s probably because u experiencing what I’ve described here : #7056, I’ll try to create PL again for this this week