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
Update operation sets boolean fields to NULL instead of false, violating non-null constraint #922
Comments
tl;dr: Try using db.NewUpdate().
Model(entity).
Column("is_active").
Value("is_active", "false"). // will substitute to is_active = false
WherePK().
Exec(ctx) This is a workaround, because the behaviour you've described looks buggy. For more about that, read on. This happens because any field that has a Lines 378 to 381 in 8a43835
Why? Because for Lines 335 to 338 in 8a43835
That's helpful, even though not all dialects support this feature (looking at you, SQLite). Lines 97 to 99 in 8a43835
I think |
Hello,
I'm currently using bun in a project and I've encountered an issue with boolean fields defaulting to NULL instead of false during updates.
Here's the bun model struct I'm using:
And here's the function I'm using to update the Entity:
In my test case, when I'm setting
IsActive
tofalse
explicitly and try to update the record, I get an error: null value in column "is_active" violates not-null constraint error, which indicates that the is_active column is being set to NULL.I've checked/debugged my code and can confirm that
IsActive
is being set to false and not NULL.This issue seems to occur only during updates when the boolean value is explicitly set to
false
.Thank you.
The text was updated successfully, but these errors were encountered: