From 1562b9896f8f614ef40fd032b1ec777280b377c1 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 6 Mar 2014 11:35:58 -0800 Subject: [PATCH] Fixed #22183: Don't make a table for M2Ms with through= --- django/db/backends/schema.py | 3 ++- django/db/models/fields/related.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index afc60c30b1..7054633b81 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -262,7 +262,8 @@ class BaseDatabaseSchemaEditor(object): }) # Make M2M tables for field in model._meta.local_many_to_many: - self.create_model(field.rel.through) + if field.rel.through._meta.auto_created: + self.create_model(field.rel.through) def delete_model(self, model): """ diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index e7b66217c5..16de0bfc74 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -2032,6 +2032,8 @@ class ManyToManyField(RelatedField): kwargs['to'] = self.rel.to else: kwargs['to'] = "%s.%s" % (self.rel.to._meta.app_label, self.rel.to._meta.object_name) + if getattr(self.rel, 'through', None) is not None: + kwargs['through'] = self.rel.through # If swappable is True, then see if we're actually pointing to the target # of a swap. swappable_setting = self.swappable_setting