transact-rs/sqlx · error

No drivers installed. Please see the documentation in `sqlx:

Error message

No drivers installed. Please see the documentation in `sqlx::any` for details.

What it means

`sqlx::any::AnyDriver::from_url` looks up installed drivers in a lazily-initialized registry (`DRIVERS`). If the registry was never populated, `.get()` panics with this message; this happens when no `sqlx-*` driver crates are registered because the `any` driver feature flags were not enabled. sqlx requires opting in to drivers via feature flags such as `sqlx = { features = ["any", "postgres"] }`.

Source

Thrown at sqlx-core/src/any/driver.rs:147

pub fn install_drivers(
    drivers: &'static [AnyDriver],
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    DRIVERS
        .set(drivers)
        .map_err(|_| "drivers already installed".into())
}

#[cfg(feature = "migrate")]
pub(crate) fn from_url_str(url: &str) -> crate::Result<&'static AnyDriver> {
    from_url(&url.parse().map_err(Error::config)?)
}

pub(crate) fn from_url(url: &Url) -> crate::Result<&'static AnyDriver> {
    let scheme = url.scheme();

    let drivers: &[AnyDriver] = DRIVERS
        .get()
        .expect("No drivers installed. Please see the documentation in `sqlx::any` for details.");

    drivers
        .iter()
        .find(|driver| driver.url_schemes.contains(&url.scheme()))
        .ok_or_else(|| {
            Error::Configuration(format!("no driver found for URL scheme {scheme:?}").into())
        })
}

View on GitHub (pinned to 03af8bcc57)

Solutions

  1. Enable the `any` feature together with the concrete driver features on the sqlx dependency: `sqlx = { version = "...", features = ["any", "postgres"] }`.
  2. Ensure the concrete driver feature is enabled in the same crate that depends on `sqlx` with `any` (Cargo features are per-crate and unify, but at least one crate in the graph must combine them).
  3. If constructing `AnyDriver` manually, call `sqlx_any::install_default_drivers()` (or register your driver) before `from_url_str`.
  4. Verify with `cargo tree -e features -p sqlx` that the driver feature is actually active in your build.

Example fix

// before (Cargo.toml)
sqlx = { version = "0.8", features = ["any"] }
let pool = AnyPool::connect("postgres://localhost/app").await?; // panics: no drivers

// after (Cargo.toml)
sqlx = { version = "0.8", features = ["any", "postgres", "sqlite"] }
let pool = AnyPool::connect("postgres://localhost/app").await?;
Defensive patterns

Strategy: validation

Validate before calling

// compile-time: assert driver features are enabled
#[cfg(not(any(feature = "postgres", feature = "mysql", feature = "sqlite")))]
compile_error!("sqlx `any` usage requires at least one concrete driver feature");

Type guard

fn scheme_is_supported(url: &str) -> bool {
    matches!(
        url.split(":").next(),
        Some("postgres") | Some("postgresql") | Some("mysql") | Some("mariadb") | Some("sqlite")
    )
}

Try / catch

// with manual driver installation, catch a panic from an empty registry
let result = std::panic::catch_unwind(|| {
    tokio::runtime::Handle::current().block_on(AnyPool::connect(url))
});
match result {
    Ok(Ok(pool)) => pool,
    Ok(Err(e)) => return Err(e.into()),
    Err(_) => panic!("AnyDriver registry empty: enable sqlx features [any, postgres|mysql|sqlite]"),
}

Prevention

When it happens

Trigger: Using `AnyPool::connect(url)` / `AnyConnection` / `AnyDriver::from_url_str` with a URL like `postgres://...` or `sqlite://...` while the corresponding driver feature (`postgres`, `mysql`, `sqlite`) is not enabled in the `sqlx` dependency, so `install_default_drivers` never ran.

Common situations: Switching an app to `sqlx::any` for runtime-selectable backends but forgetting to add the concrete driver features; workspace builds where `any` is enabled in one crate but driver features are not propagated (features are additive per-crate, so they must be enabled on the same `sqlx` dependency that has `any` enabled somewhere in the graph).

Related errors


AI-assisted analysis of transact-rs/sqlx@03af8bcc57 (2026-09-03). Data as JSON: /api/errors/e803a9cbe994e501. Report an issue: GitHub.