You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query bypassing SQLx compile-time checks for missing NOT NULL column
Background
I've recently added a new required column to my database but I'm noticing that my SQLx query is still compiling successfully despite not including this column. Here's what I've done:
Added a migration that adds a NOT NULL column to my table:
I expected SQLx to produce a compile-time error because my query doesn't include the new user_id column that's marked as NOT NULL in the database schema.
Actual Behavior
The code compiles successfully but fails at runtime with a PostgreSQL error about violating the not-null constraint.
Environment Details
Database: PostgreSQL
Rust version: 1.85
SQLx Dependency: sqlx = { version = "0.8.3", features = ["runtime-tokio-native-tls", "postgres", "macros", "uuid", "time"] }
Questions
Why isn't SQLx catching this missing required column at compile time?
Is there a configuration I need to enable to ensure these kinds of errors are caught during compilation?
Could this indicate an issue with how my database connection is set up for compile-time checking?
Thank you for any insights on how to resolve this! I really value the compile-time checking feature of SQLx and want to make sure I'm using it correctly.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Query bypassing SQLx compile-time checks for missing NOT NULL column
Background
I've recently added a new required column to my database but I'm noticing that my SQLx query is still compiling successfully despite not including this column. Here's what I've done:
Restarted my database to ensure changes are applied.
My query still compiles despite not including the new required column:
Expected Behavior
I expected SQLx to produce a compile-time error because my query doesn't include the new
user_id
column that's marked as NOT NULL in the database schema.Actual Behavior
The code compiles successfully but fails at runtime with a PostgreSQL error about violating the not-null constraint.
Environment Details
Questions
Thank you for any insights on how to resolve this! I really value the compile-time checking feature of SQLx and want to make sure I'm using it correctly.
Beta Was this translation helpful? Give feedback.
All reactions