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.