-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat: return null if no defaultValue is specified #14682
Conversation
src/sequelize.js
Outdated
@@ -1271,6 +1271,10 @@ Use Sequelize#query if you wish to use replacements.`); | |||
} | |||
} | |||
|
|||
if (attribute.allowNull !== false && !attribute.defaultValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultValue
could be 0, or ''
, a better check would be:
if (attribute.allowNull !== false && !attribute.defaultValue) { | |
if (attribute.allowNull !== false && attribute.defaultValue === undefined) { |
It's also a good opportunity to normalize attribute.allowNull
just before this so the test can be reduced to
if (attribute.allowNull !== false && !attribute.defaultValue) { | |
if (attribute.allowNull && attribute.defaultValue === undefined) { |
The only element I was worried about was https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html, but after checking I think this is a safe change (but the tests need to be updated) |
Do we want to do #14260 in v7? I was thinking of postponing it to v8 to reduce how many impactful breaking changes we have, and maybe add the flag to change the default nullability in v7? |
I think this PR can be undrafted once #14715 is complete, that other PR should implement the missing pieces |
We still have an open issue connected to this, I'll close this for now and we can revisit with that issue later |
Pull Request Checklist
Please make sure to review and check all of these items:
yarn test
oryarn test-DIALECT
pass with this change (including linting)?Description Of Change
This PR adds a defaultValue of
null
if there is no defaultValue specified when creating a model and the attribute allowsnull
.This fixes #14671.
@ephys I'm not so sure about this change. As you can see the unit tests fail because it also adds
DEFAULT NULL
to the SQL query. Is that wanted behaviour? This might even qualify as a breaking changeTodos