Documentation Index
Fetch the complete documentation index at: https://mintlify.com/launchbadge/sqlx/llms.txt
Use this file to discover all available pages before exploring further.
sqlx.toml is an optional configuration file that lives in your crate root alongside Cargo.toml. It lets you control how the query! macro family maps SQL types to Rust types, override the migration table name, customize the migrations directory, and more. Configuration in sqlx.toml applies only to the crate that contains the file — it is not inherited by workspace members.
The
sqlx-toml feature flag must be enabled to parse this file. If SQLx finds a sqlx.toml but the feature is disabled, it will emit a compile error.File location
Placesqlx.toml next to Cargo.toml in your crate root. The macros locate it using the CARGO_MANIFEST_DIR environment variable that Cargo sets at compile time. sqlx-cli reads the same file from the current working directory when running migrations.
[common]
Shared settings used by both the macros and sqlx-cli.
| Key | Type | Default | Description |
|---|---|---|---|
database-url-var | string | "DATABASE_URL" | The environment variable used to find the database URL. |
[macros]
Configuration for the query!() family of macros. All settings here are applied at compile time only.
[macros.preferred-crates]
When two optional type-integration features are both enabled by Cargo’s feature unification (for example, a dependency activates time while your crate uses chrono), SQLx would otherwise pick one arbitrarily. Use preferred-crates to resolve the ambiguity globally.
| Key | Values | Default | Description |
|---|---|---|---|
date-time | "chrono", "time" | "inferred" | Which crate to use for DATE, TIME, DATETIME, and TIMESTAMP columns. |
numeric | "bigdecimal", "rust_decimal" | "inferred" | Which crate to use for NUMERIC / DECIMAL columns. |
"inferred", time takes precedence over chrono, and rust_decimal takes precedence over bigdecimal.
[macros.type-overrides]
Map SQL type names to specific Rust types for all queries in the crate. Keys are SQL type names (case-sensitive, quoted for safety); values are fully-qualified Rust type paths.
Type overrides affect only the inner Rust type. They do not change whether
query!() wraps a column in Option<_> — nullability is still inferred from the database schema.[macros.table-overrides]
Override type mappings on a per-table, per-column basis. Useful when the same SQL type name maps to different Rust types in different tables.
[migrate]
Configuration for migrations run via sqlx::migrate!() or sqlx-cli.
| Key | Type | Default | Description |
|---|---|---|---|
table-name | string | "_sqlx_migrations" | The table used to track applied migrations. May be schema-qualified. |
migrations-dir | string | "migrations" | Directory containing migration files, relative to the crate root (for sqlx::migrate!()) or current directory (for sqlx-cli). |
ignored-chars | array of strings | [] | Characters to strip before hashing migration files (e.g. ["\r"] to normalize line endings). |
[migrate.defaults]
Default settings used by sqlx migrate create.
| Key | Values | Default | Description |
|---|---|---|---|
migration-type | "simple", "reversible" | "inferred" | Whether new migrations are simple (up-only) or reversible (up + down). "inferred" matches the last existing migration. |
migration-versioning | "timestamp", "sequential" | "inferred" | Versioning scheme for new migration filenames. "inferred" matches the last existing migration. |