The automatic ID field would not be added if you have a primary key. I'm
not sure if inspectdb does pick up primary keys, I believe it does though.

I feel this discussion may be more suited to django-users, our forum for
helping debugging user issues.

Marc

On 28 April 2015 at 07:48, Ben L <benincam...@gmail.com> wrote:

> Issue: I have an existing database, so the guide in
> https://docs.djangoproject.com/en/1.8/howto/legacy-databases/ to inspect
> db and created models.py .
>
> That table does NOT have an 'id' column, and the created models.py doesn't
> have 'id' either, and the class is unmanaged (managed=False). But when I
> use Django to create page, the system failed, saying the 'id' is not found
> in the table. Somehow the query included 'id' in the select fields.
>
> After a little bit of digging, I changed
> /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)
>
> Then my class will not get into this "AutoField" action to add 'id' in the
> query.
>
> Looks like an apparent bug. This change works well for me. Please check
> and confirm whether this should be commit into you code base.
>
> Thanks.
>
>
>  --
> 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/7dd7a80b-3b7c-4cb1-ab31-219c6c3ad3c5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/7dd7a80b-3b7c-4cb1-ab31-219c6c3ad3c5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMwjO1HBgpHwwMQvNOE0GkKK%3D3EQE_jAF7SnUR5nnOJE6%2Bmzeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to