From b7dbd708fad2c0e6b8dcb28a83550a926551d31b Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 6 Sep 2024 15:10:46 -0400 Subject: [PATCH] make create/delete_model() handle M2M tables --- django_mongodb/features.py | 3 --- django_mongodb/schema.py | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 441647901..e3cc4aee1 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -126,9 +126,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): "schema.tests.SchemaTests.test_remove_unique_together_does_not_remove_meta_constraints", "schema.tests.SchemaTests.test_unique_together", # ManyToManyField - "schema.tests.SchemaTests.test_m2m_create", - "schema.tests.SchemaTests.test_m2m_create_custom", - "schema.tests.SchemaTests.test_m2m_create_inherited", "schema.tests.SchemaTests.test_m2m_rename_field_in_target_model", "schema.tests.SchemaTests.test_m2m_repoint", "schema.tests.SchemaTests.test_m2m_repoint_custom", diff --git a/django_mongodb/schema.py b/django_mongodb/schema.py index 3bc7fcb2b..896ad8dd2 100644 --- a/django_mongodb/schema.py +++ b/django_mongodb/schema.py @@ -4,8 +4,16 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def create_model(self, model): self.connection.database.create_collection(model._meta.db_table) + # Make implicit M2M tables. + for field in model._meta.local_many_to_many: + if field.remote_field.through._meta.auto_created: + self.create_model(field.remote_field.through) def delete_model(self, model): + # Delete implicit M2m tables. + for field in model._meta.local_many_to_many: + if field.remote_field.through._meta.auto_created: + self.delete_model(field.remote_field.through) self.connection.database[model._meta.db_table].drop() def add_field(self, model, field):