diesel-rs/diesel · error
no `#[diesel(sql_type = ...)]` attribute provided
Error message
no `#[diesel(sql_type = ...)]` attribute provided
What it means
The `AsExpression`/`FromSqlRow` derive for enums (or newtype usage) requires at least one `#[diesel(sql_type = ...)]` attribute so it knows which SQL types to implement for. If none are found on the item, the derive fails at enum_.rs:245 with this error.
Solutions
- Add `#[diesel(sql_type = Int4)]` (or the appropriate type) to the enum.
- If you need several SQL representations, add multiple `#[diesel(sql_type = ...)]` attributes.
- Update old 1.x syntax `#[sql_type = "Int4"]` to the Diesel 2.x `#[diesel(sql_type = ...)]` form.
Example fix
// before
#[derive(AsExpression, FromSqlRow)]
pub enum Status { Active, Retired }
// after
#[derive(AsExpression, FromSqlRow)]
#[diesel(sql_type = Int4)]
pub enum Status { Active, Retired } Defensive patterns
Strategy: validation
Validate before calling
// Verify the enum carries at least one diesel sql_type attribute:
// #[derive(AsExpression, FromSqlRow)]
// #[diesel(sql_type = Int4)]
// pub enum MyEnum { ... } Prevention
- Always pair AsExpression/FromSqlRow enum derives with `#[diesel(sql_type = ...)]`.
- Migrate Diesel 1.x `#[sql_type = "..."]` syntax to 2.x `#[diesel(sql_type = ...)]`.
- Check for typos: the attribute must be `sql_type` inside the `diesel` namespace.
When it happens
Trigger: Deriving diesel traits on an enum without any `#[diesel(sql_type = X)]` attribute at the enum level, or misspelling/renesting the attribute (e.g. `#[diesel(sql_type=X)]` outside the `#[diesel(...)]` group or writing `#[sql_type(...)]`, the old pre-2.0 form).
Common situations: Migrating from Diesel 1.x where `#[sql_type = "..."]` was top-level; forgetting the attribute after copying an enum example without it; typos like `sqltype`.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- expected a integer literal expression, but got something…
- all fields of tuple structs must be annotated with…
- `embed` and `treat_none_as_default_value` are mutually…
- `#[diesel(embed)]` cannot be combined with…
- this derive can only be used on non-unit structs
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/7dce3c879cf51d1b.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_derives/src/enum_.rs:245
let sql_type_attrs = attrs
.into_iter()
.filter_map(
|a: AttributeSpanWrapper<diesel_attribute_parser::StructAttr>| {
if let diesel_attribute_parser::StructAttr::SqlType(_, path) = a.item {
Some(diesel_attribute_parser::AttributeSpanWrapper {
item: path,
attribute_span: a.attribute_span,
ident_span: a.ident_span,
})
} else {
None
}
},
)
.collect::<Vec<_>>();
if sql_type_attrs.is_empty() {
return Err(syn::Error::new(
input_span,
"no `#[diesel(sql_type = ...)]` attribute provided",
));
}
Ok(Self {
sql_type_attrs,
ident: input.ident,
has_explicit_discriminants,
variants,
})
}
}
View on GitHub (pinned to 6fa6ed01b2)