{"record":{"id":"a0afa40ba4b71883","repo":"diesel-rs/diesel","slug":"expected-valid-identifier-found-0-diesel-doe","errorCode":null,"errorMessage":"expected valid identifier, found `{0}`. Diesel does not support column names with whitespaces yet","messagePattern":"expected valid identifier, found `(.+?)`\\. Diesel does not support column names with whitespaces yet","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_attribute_parser/src/lib.rs","lineNumber":99,"sourceCode":"\n#[derive(Clone)]\npub struct SqlIdentifier {\n    field_name: String,\n    span: Span,\n}\n\nimpl SqlIdentifier {\n    pub fn span(&self) -> Span {\n        self.span\n    }\n\n    pub fn to_ident(&self) -> Result<Ident> {\n        match syn::parse_str::<Ident>(&format!(\"r#{}\", self.field_name)) {\n            Ok(mut ident) => {\n                ident.set_span(self.span);\n                Ok(ident)\n            }\n            Err(_e) if self.field_name.contains(' ') => Err(syn::Error::new(\n                self.span(),\n                format!(\n                    \"expected valid identifier, found `{0}`. \\\n                 Diesel does not support column names with whitespaces yet\",\n                    self.field_name\n                ),\n            )),\n            Err(_e) => Err(syn::Error::new(\n                self.span(),\n                format!(\n                    \"expected valid identifier, found `{0}`. \\\n                 Diesel automatically renames invalid identifiers, \\\n                 perhaps you meant to write `{0}_`?\",\n                    self.field_name\n                ),\n            )),\n        }\n    }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_attribute_parser/src/lib.rs#L81-L117","documentation":"Diesel's field-name-to-identifier conversion tries to parse the field name as a raw Rust identifier (`r#<name>`); when that fails and the name contains a space, it reports that the name is not a valid identifier because Diesel does not yet support column names with whitespace.","triggerScenarios":"Deriving diesel traits where a `#[sql_name = \"my column\"]`/column name contains a space, causing `to_ident` to attempt `r#my column` which is not a valid Rust identifier.","commonSituations":"Mapping to legacy database schemas with column names containing spaces, quoting, or special characters that Rust identifiers cannot represent.","solutions":["Rename the database column to remove whitespace (e.g. `my_column`)","Use a Rust-safe field name in your struct and map it explicitly via the supported column-name mechanism","Handle the column outside diesel derives (raw SQL queries) if the schema cannot change"],"exampleFix":"// before\n#[sql_name = \"my column\"]\nmy_column: String,\n// after\n#[sql_name = \"my_column\"]\nmy_column: String,\n// or rename the DB column to `my_column`","handlingStrategy":"validation","validationCode":"fn diesel_safe_column_name(name: &str) -> bool {\n    !name.is_empty() && !name.contains(char::is_whitespace) && syn::parse_str::<syn::Ident>(&format!(\"r#{}\", name)).is_ok()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate DB column names for whitespace/invalid chars before generating diesel models","Rename legacy columns with spaces during schema migrations","Keep struct field names and sql_name mappings identifier-safe"],"tags":["rust","diesel-derive","identifier","naming"],"backgroundTag":"invalid-identifier","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"}