#32893: Missing import statement in generated migration (NameError: name 
'models'
is not defined)
-------------------------------------+-------------------------------------
     Reporter:  Jaap Joris Vens      |                    Owner:  Abhyudai
         Type:  Bug                  |                   Status:  assigned
    Component:  Migrations           |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:  migrations writer    |             Triage Stage:  Accepted
  missing import                     |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

 `MyBaseModel` is not necessary to reproduce this issue, it's due to the
 fact that `MyModel` doesn't have fields from `django.db.models` and has
 custom `bases`. It looks like an issue with special casing of
 `models.Model` in `TypeSerializer`. Proposed patch

 {{{
 diff --git a/django/db/migrations/serializer.py
 b/django/db/migrations/serializer.py
 index e19c881cda..6e78462e95 100644
 --- a/django/db/migrations/serializer.py
 +++ b/django/db/migrations/serializer.py
 @@ -273,7 +273,7 @@ class TupleSerializer(BaseSequenceSerializer):
  class TypeSerializer(BaseSerializer):
      def serialize(self):
          special_cases = [
 -            (models.Model, "models.Model", []),
 +            (models.Model, "models.Model", ['from django.db import
 models']),
              (type(None), 'type(None)', []),
          ]
          for case, string, imports in special_cases:
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32893#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.88500b92a6fd9902e127bc57f70b55f2%40djangoproject.com.

Reply via email to