Django Version: (1, 8, 0, 'final', 0)

Issue: I have an existing database, so I integrated it following the
instruction in https://docs.djangoproject.com/en/1.8/howto/legacy-databases/
to inspectdb and generated models.py. That table does NOT have column 'id',
so the generated models.py doesn't have 'id' either. The model is unmanaged
(managed = False).
But the Django page failed, saying something like 'can not find id column
in the table'. Somehow the query added 'id' in the select fields.


Fixed: Modified
/usr/local/lib/python2.7/dist-packages/django/db/models/options.py
Old: line 284-287
            else:
                auto = AutoField(verbose_name='ID', primary_key=True,
                            auto_created=True)
                model.add_to_class('id', auto)
New:
            else:
                if self.managed:
                    auto = AutoField(verbose_name='ID', primary_key=True,
                            auto_created=True)
                    model.add_to_class('id', auto)

That works well for my system. I think it makes sense that Django should
not add AutoField for unmanaged class.

Please confirm and decide whether to patch this into your code base. Thanks.






Ben Lin
http://benincampus.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAAqSmN6mFjy6CbOuM2ywM2LsQ-6ryEVvCOakkp2Mw5Wiboj0Jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to