0
votes

Getting django.db.utils.DatabaseError: ORA-00918: column ambiguously defined error when I try to open Django admin page. Here is the error:

raise dj_exc_value.with_traceback(traceback) from exc_value File "/venomscribe/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/venomscribe/lib/python3.6/site-packages/django/db/backends/oracle/base.py", line 514, in execute return self.cursor.execute(query, self._param_generator(params)) django.db.utils.DatabaseError: ORA-00918: column ambiguously defined

Query is

SELECT "DJANGO_ADMIN_LOG"."ID",
       "DJANGO_ADMIN_LOG"."ACTION_TIME",
       "DJANGO_ADMIN_LOG"."USER_ID",
       "DJANGO_ADMIN_LOG"."CONTENT_TYPE_ID",
       "DJANGO_ADMIN_LOG"."OBJECT_ID",
       "DJANGO_ADMIN_LOG"."OBJECT_REPR",
       "DJANGO_ADMIN_LOG"."ACTION_FLAG",
       "DJANGO_ADMIN_LOG"."CHANGE_MESSAGE",
       "AUTH_USER"."ID",
       "AUTH_USER"."PASSWORD",
       "AUTH_USER"."LAST_LOGIN",
       "AUTH_USER"."IS_SUPERUSER",
       "AUTH_USER"."USERNAME",
       "AUTH_USER"."FIRST_NAME",
       "AUTH_USER"."LAST_NAME",
       "AUTH_USER"."EMAIL",
       "AUTH_USER"."IS_STAFF",
       "AUTH_USER"."IS_ACTIVE",
       "AUTH_USER"."DATE_JOINED",
       "DJANGO_CONTENT_TYPE"."ID",
       "DJANGO_CONTENT_TYPE"."APP_LABEL",
       "DJANGO_CONTENT_TYPE"."MODEL"
  FROM "DJANGO_ADMIN_LOG"
  INNER JOIN "AUTH_USER"
    ON ("DJANGO_ADMIN_LOG"."USER_ID" = "AUTH_USER"."ID")
  LEFT OUTER JOIN "DJANGO_CONTENT_TYPE"
    ON ("DJANGO_ADMIN_LOG"."CONTENT_TYPE_ID" = "DJANGO_CONTENT_TYPE"."ID")
  WHERE "DJANGO_ADMIN_LOG"."USER_ID" = :arg0
  ORDER BY "DJANGO_ADMIN_LOG"."ACTION_TIME" DESC
  FETCH FIRST 10 ROWS ONLY
2

2 Answers

1
votes

It was system requirement issue. I was using oracle 12.1 which is not compatible with django 3.0.3. Downgrading to 2.2 resolved the issue.

0
votes

You're fetching DJANGO_ADMIN_LOG.ID, AUTH_USER.ID, and DJANGO_CONTENT_TYPE.ID, so you're trying to have three ID columns in your result set. This is not allowed. I suggest you alias these columns so you can distinguish between them:

SELECT l.ID AS DJANGO_ADMIN_LOG_ID,
       l.ACTION_TIME,
       l.USER_ID,
       l.CONTENT_TYPE_ID,
       l.OBJECT_ID,
       l.OBJECT_REPR,
       l.ACTION_FLAG,
       l.CHANGE_MESSAGE,
       u.ID AS AUTH_USER_ID,
       u.PASSWORD,
       u.LAST_LOGIN,
       u.IS_SUPERUSER,
       u.USERNAME,
       u.FIRST_NAME,
       u.LAST_NAME,
       u.EMAIL,
       u.IS_STAFF,
       u.IS_ACTIVE,
       u.DATE_JOINED,
       t.ID AS DJANGO_CONTENT_TYPE_ID,
       t.APP_LABEL,
       t.MODEL
  FROM DJANGO_ADMIN_LOG l
  INNER JOIN AUTH_USER u
    ON l.USER_ID = u.ID
  LEFT OUTER JOIN DJANGO_CONTENT_TYPE t
    ON l.CONTENT_TYPE_ID = t.ID
  WHERE l.USER_ID = :arg0
  ORDER BY l.ACTION_TIME DESC
  FETCH FIRST 10 ROWS ONLY

I also suggest you use white space and table aliases to make the query easier to read.