-
When generating models with the sea-orm-cli, if you have a column with a name that conflicts with a Rust keyword, the cli crashes and is not handled correctly. For example, an SQL table:
I get an error:
This is caused because the column Any rust columns conflicting should be renamed to resolve this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 5 replies
-
Any suggestion on the naming convention? How about an underscore at the end? |
Beta Was this translation helpful? Give feedback.
-
I didn't make any suggestions for this because I am not sure 😄 I guess |
Beta Was this translation helpful? Give feedback.
-
I think we can leave it for the user to decide how to resolve the name conflict. Personally think that neither #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
pub id: i32,
pub type_of: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveCustomColumn)]
pub enum Column {
Id,
TypeOf,
}
impl IdenStatic for Column {
fn as_str(&self) -> &str {
match self {
Self::TypeOf => "type",
_ => self.default_as_str(),
}
}
} |
Beta Was this translation helpful? Give feedback.
-
The problem is that users will integrate existing databases with SeaORM.. and usually you don't want your framework / language to dictate your database, it should be flexible enough to avoid issues like this |
Beta Was this translation helpful? Give feedback.
-
Good point! |
Beta Was this translation helpful? Give feedback.
-
I think we didn't require the database schema to change here. Just a change in Rust's Entity definition. And the trick is to simply use a non Rust keyword in the enum variant and struct attribute, and map to the actual underlying table column. |
Beta Was this translation helpful? Give feedback.
-
Has any progress been made on this? My schema uses |
Beta Was this translation helpful? Give feedback.
I think we can leave it for the user to decide how to resolve the name conflict.
Personally think that neither
r#type
nortype_
be a good option. For me, I would simply choose another name to avoid conflicting with Rust keywords.