{"record":{"id":"7dce3c879cf51d1b","repo":"diesel-rs/diesel","slug":"no-diesel-sql-type-attribute-provided","errorCode":null,"errorMessage":"no `#[diesel(sql_type = ...)]` attribute provided","messagePattern":"no `#\\[diesel\\(sql_type = \\.\\.\\.\\)\\]` attribute provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_derives/src/enum_.rs","lineNumber":245,"sourceCode":"\n        let sql_type_attrs = attrs\n            .into_iter()\n            .filter_map(\n                |a: AttributeSpanWrapper<diesel_attribute_parser::StructAttr>| {\n                    if let diesel_attribute_parser::StructAttr::SqlType(_, path) = a.item {\n                        Some(diesel_attribute_parser::AttributeSpanWrapper {\n                            item: path,\n                            attribute_span: a.attribute_span,\n                            ident_span: a.ident_span,\n                        })\n                    } else {\n                        None\n                    }\n                },\n            )\n            .collect::<Vec<_>>();\n        if sql_type_attrs.is_empty() {\n            return Err(syn::Error::new(\n                input_span,\n                \"no `#[diesel(sql_type = ...)]` attribute provided\",\n            ));\n        }\n\n        Ok(Self {\n            sql_type_attrs,\n            ident: input.ident,\n            has_explicit_discriminants,\n            variants,\n        })\n    }\n}\n","sourceCodeStart":227,"sourceCodeEnd":259,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/enum_.rs#L227-L259","documentation":"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.","triggerScenarios":"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).","commonSituations":"Migrating from Diesel 1.x where `#[sql_type = \"...\"]` was top-level; forgetting the attribute after copying an enum example without it; typos like `sqltype`.","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."],"exampleFix":"// before\n#[derive(AsExpression, FromSqlRow)]\npub enum Status { Active, Retired }\n\n// after\n#[derive(AsExpression, FromSqlRow)]\n#[diesel(sql_type = Int4)]\npub enum Status { Active, Retired }","handlingStrategy":"validation","validationCode":"// Verify the enum carries at least one diesel sql_type attribute:\n// #[derive(AsExpression, FromSqlRow)]\n// #[diesel(sql_type = Int4)]\n// pub enum MyEnum { ... }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["proc-macro","derive","missing-attribute","compile-time"],"backgroundTag":"missing-required-argument","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}