Django fails to model legacy database with inspectdb
Asked Answered
O

1

10

I have a currently empty Geodjango app set up - I am connected to my Postgis database in which I have a table named aadf that I am attempting to create a model from. I am using inspectdb to do this.

I get the following error message:

from django.contrib.gis.db import models
# Unable to inspect table 'aadf'
# The error was: sequence index must be integer, not 'slice'
# Unable to inspect table 'auth_group'
# The error was: sequence index must be integer, not 'slice'
# Unable to inspect table 'auth_group_permissions'
# The error was: sequence index must be integer, not 'slice'

** This error message repeats for multiple other tables that Django has created **

The connection to the database evidently seems fine as it is able to pick up the relevant table name. That said, it also seems to be trying to inspect the other tables Django has created in the database such as 'auth_group' and 'auth_group_permissions'.

Outshoot answered 5/4, 2019 at 8:25 Comment(4)
What is your Django version?Ctesiphon
I'm using django 2.2Outshoot
You can inspect just one table.Bonina
Thanks - unfortunately I still get "# The error was: sequence index must be integer, not 'slice'" when only doing it on the relevant table.Outshoot
M
20

I got this error and found that it was caused by using psycopg2 version 2.8 (or 2.8.1) -- downgrading to 2.7.7 made it go away. This is on Windows 10 with Django 2.2.

Edit: I see now that there's a fix in the pipeline for Django 2.2 to support psycopg2 2.8.

Edit (5/1/2019): Django 2.2.1 is out today with a fix adding support for psycopg2 2.8.

Marismarisa answered 9/4, 2019 at 18:55 Comment(3)
Thank you so so much for this. Project was at a complete standstill and wouldn't have been able to work this out. EDIT: I used the following command to downgrade psycopg2 'pip install psycopg2==2.7.7 --force-reinstall'Outshoot
What is the bug# for this? Would be helpful to track the version with the fix!Shields
FWIW: also pip of psycopg2-2.8.5-cp38-cp38-linux_x86_64.whl with Django 1.11 workedRothermere

© 2022 - 2024 — McMap. All rights reserved.