diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index dc60654fa..9eadeae0d 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -460,15 +460,23 @@ impl EntityWriter { entity .columns .iter() - .fold(TokenStream::new(), |mut ts, col| { - if let sea_query::ColumnType::Enum { name, .. } = col.get_inner_col_type() { - let enum_name = format_ident!("{}", name.to_string().to_upper_camel_case()); - ts.extend([quote! { - use super::sea_orm_active_enums::#enum_name; - }]); - } - ts - }) + .fold( + (TokenStream::new(), Vec::new()), + |(mut ts, mut enums), col| { + if let sea_query::ColumnType::Enum { name, .. } = col.get_inner_col_type() { + if !enums.contains(&name) { + enums.push(name); + let enum_name = + format_ident!("{}", name.to_string().to_upper_camel_case()); + ts.extend([quote! { + use super::sea_orm_active_enums::#enum_name; + }]); + } + } + (ts, enums) + }, + ) + .0 } pub fn gen_model_struct(