#29177: Unmanaged models with ForeignKeys do not get those fields serialized 
into
their migration state when CreateModel happens.
------------------------------+------------------------------------
     Reporter:  Keryn Knight  |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  Migrations    |                  Version:  master
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  1             |      Needs documentation:  1
  Needs tests:  0             |  Patch needs improvement:  1
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------

Comment (by YBull):

 Using version 2.0.5, I just encountered this bug and when trying to work
 around it, discovered that it's a little more expansive than the example
 model with A, B, C above shows.  In my case, I had used the 'inspectdb'
 command to generate models for 12 legacy tables (all with managed =
 False).  The inspectdb command did a reasonably good job and included all
 the ForeignKey fields it should have.  But even after I commented out the
 lines in autodetector.py to work around this bug, I discovered that the
 'makemigrations' command still has another related problem with Fkeys on
 unmanaged models.  Specifically, whenever a new unmanaged model is
 referenced by another model's Fkeys, you must run 'makemigrations' for the
 referenced table BEFORE adding the model(s) containing the reference.  So
 in my case, even though the models.py was valid and complete at the
 beginning, I had to temporarily remove all the new dependent models to
 carefully generate a sequence of six separate migrations to get all my 12
 legacy tables in with the correct FKey declarations in the migration
 scripts.

 Being new to Django and the code base, I wanted to report this here, but
 I'm not sure whether the fix for this aspect is actually a separate
 related bug.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29177#comment:5>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.45f4778eb37f50621319e6d7da7932fb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to