Skip to content

Commit e8574a8

Browse files
committed
Merge branch 'dev'
2 parents c37bc45 + a0365ef commit e8574a8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/make_migrations/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn run_make_migrations(options: MakeMigrationsOptions) -> anyhow::Result<()>
220220
})
221221
}
222222

223-
let mut references: HashMap<String, Field> = HashMap::new();
223+
let mut references: HashMap<String, Vec<Field>> = HashMap::new();
224224

225225
// Create migration operations for new models
226226
new_models.iter().for_each(|x| {
@@ -231,7 +231,10 @@ pub fn run_make_migrations(options: MakeMigrationsOptions) -> anyhow::Result<()>
231231
.iter()
232232
.any(|z| z.eq_shallow(&Annotation::ForeignKey(Default::default())))
233233
{
234-
references.insert(x.name.clone(), y.clone());
234+
references
235+
.entry(x.name.clone())
236+
.or_default()
237+
.push(y.clone());
235238
} else {
236239
normal_fields.push(y.clone());
237240
}
@@ -245,8 +248,13 @@ pub fn run_make_migrations(options: MakeMigrationsOptions) -> anyhow::Result<()>
245248
});
246249

247250
// Create referencing fields for new models
248-
for (model, field) in references {
249-
op.push(Operation::CreateField { model, field });
251+
for (model, fields) in references {
252+
for field in fields {
253+
op.push(Operation::CreateField {
254+
model: model.clone(),
255+
field,
256+
});
257+
}
250258
}
251259

252260
// Create migration operations for deleted models

0 commit comments

Comments
 (0)