Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21438: makemigrations now detects ManyToManyFields

  • Loading branch information...
commit 5e63977c0e5d0dff755817b86364a5c8882deaf7 1 parent 19b34fb
Andrew Godwin authored November 27, 2013
4  django/db/migrations/state.py
@@ -100,6 +100,10 @@ def from_model(cls, model):
100 100
             name, path, args, kwargs = field.deconstruct()
101 101
             field_class = import_by_path(path)
102 102
             fields.append((name, field_class(*args, **kwargs)))
  103
+        for field in model._meta.local_many_to_many:
  104
+            name, path, args, kwargs = field.deconstruct()
  105
+            field_class = import_by_path(path)
  106
+            fields.append((name, field_class(*args, **kwargs)))
103 107
         # Extract the options
104 108
         options = {}
105 109
         for name in DEFAULT_NAMES:
4  tests/migrations/test_state.py
@@ -36,6 +36,7 @@ class Meta:
36 36
         class Book(models.Model):
37 37
             title = models.CharField(max_length=1000)
38 38
             author = models.ForeignKey(Author)
  39
+            contributors = models.ManyToManyField(Author)
39 40
 
40 41
             class Meta:
41 42
                 app_label = "migrations"
@@ -59,9 +60,10 @@ class Meta:
59 60
 
60 61
         self.assertEqual(book_state.app_label, "migrations")
61 62
         self.assertEqual(book_state.name, "Book")
62  
-        self.assertEqual([x for x, y in book_state.fields], ["id", "title", "author"])
  63
+        self.assertEqual([x for x, y in book_state.fields], ["id", "title", "author", "contributors"])
63 64
         self.assertEqual(book_state.fields[1][1].max_length, 1000)
64 65
         self.assertEqual(book_state.fields[2][1].null, False)
  66
+        self.assertEqual(book_state.fields[3][1].__class__.__name__, "ManyToManyField")
65 67
         self.assertEqual(book_state.options, {"verbose_name": "tome", "db_table": "test_tome"})
66 68
         self.assertEqual(book_state.bases, (models.Model, ))
67 69
 

0 notes on commit 5e63977

Please sign in to comment.
Something went wrong with that request. Please try again.