Drizzle ORM — column type mismatch on query
Drizzle ORM throws a type error or runtime error because the column type in the schema does not match the actual database column type or the query value.
Symptoms
- TypeError: expected number but got string
- Query fails with "invalid input syntax for type integer"
- TypeScript compiles but runtime query fails
Possible causes
- The schema defines a column as integer but the database has it as text
- A query passes a string where a number is expected
- The column was changed in the database but not in the schema
Diagnosis steps
Compare schema and database column types
npx drizzle-kit introspectInterpretation
Introspection shows the actual database types to compare against the schema.
Check the query input types
grep -n "where" src/queries.tsInterpretation
Ensure the value type matches the column type definition.
Root cause
The Drizzle schema column type does not match the database column type, so the query sends a value in the wrong format and the database rejects it.
Fix
Update the schema to match the database, run a migration to change the database type, or cast the query value to the correct type.
Verify the fix
Run the query and confirm it succeeds; verify the returned data has the correct types.
Symptom walkthrough
Drizzle ORM throws a type error or runtime error because the column type in the schema does not match the actual database column type or the query value. The error appears in production but may not surface in local development because the conditions that trigger it depend on the deployment environment or runtime configuration. Understanding the full symptom set helps distinguish this issue from similar errors.
Diagnosis in practice
Follow the diagnosis steps in the frontmatter to isolate the cause. Each step includes a command and an interpretation of the output. The goal is to narrow down whether the issue is in the configuration, the runtime, or the application code. Reproduce the error in a minimal setup before applying a fix.
Root cause
The Drizzle schema column type does not match the database column type, so the query sends a value in the wrong format and the database rejects it.
Fix
Update the schema to match the database, run a migration to change the database type, or cast the query value to the correct type. After applying the fix, monitor the system to confirm the error does not recur under load or in different environments.
Verification
Run the query and confirm it succeeds; verify the returned data has the correct types. If the verification passes, the fix is confirmed; if not, re-examine the diagnosis steps for missed contributing factors.
Diagnostic commands
Run these commands to reproduce and diagnose the issue:
npx drizzle-kit introspect
grep -n "where" src/queries.ts