Re: Syncdb Error With Oracle Database - IntegrityError Exception

237 views
Skip to first unread message

Amyth Arora

unread,
Aug 31, 2012, 2:10:36 AM8/31/12
to django...@googlegroups.com
Hey Jon,

I guess this is because of a bug in django. Django already has a open ticket for this bug. Check it out here

On Fri, Aug 31, 2012 at 7:17 AM, Jon Blake <jc.b...@gmail.com> wrote:
Just discovered Django and trying out the Django 1.4 tutorial with an Oracle backend database. In my database, I have created user django with privs create session, create table, create sequence, create trigger. The DATABASES dictionary in settings has been edited to set the default settings to the Oracle engine, and the database name, user and password specified.

When I run:

$ python manage.py syncdb

I see tables are created, but I also get a traceback ending with:

File "/usr/lib/python2.7/site-packages/django/db/backends/oracle/base.py", line 675, in execute
    return self.cursor.execute(query, self._param_generator(params))
django.db.utils.IntegrityError: ORA-01400: cannot insert NULL into ("DJANGO"."AUTH_PERMISSION"."ID")

I did not see a prompt to create a superuser account.

Oracle SQL*Developer shows that schema django contains 9 tables (including auth_permission), 16 indexes, 7 triggers and 8 sequences. Table django_content_type contains three rows, and the others are empty.

Can anyone advise on how to resolve the ORA-01400 error?

Run-time environment:
  O/S: Fedora 14
  Django: 1.4.1
  Python: 2.7
  DB: Oracle Database 11.1.0.6.0
  cx_Oracle client: 11.1.0.6.0



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/O5XePWI1ee4J.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
----------------------------

Amyth [Admin - Techstricks]
Email - aroras....@gmail.com, ad...@techstricks.com
Twitter - @a_myth_________
http://techstricks.com/

Ian

unread,
Aug 31, 2012, 11:23:28 AM8/31/12
to django...@googlegroups.com
On Friday, August 31, 2012 12:10:54 AM UTC-6, Amyth wrote:
Hey Jon,

I guess this is because of a bug in django. Django already has a open ticket for this bug. Check it out here


As described in that ticket, the reason for the problem is probably just that the Django user does not have the CREATE TRIGGER privilege, which it needs.  The bug in Django is just that this condition is not detected and reported at the time the table is created, instead of getting a rather more obscure error message at the time the table is populated.

Jon Blake

unread,
Sep 1, 2012, 12:03:42 AM9/1/12
to django...@googlegroups.com
Thanks, Ian and Amyth, for your responses.

I encountered the CREATE TRIGGER privilege issue early in my trials with Django with the Oracle database back end - Django propagated an Oracle "insufficient privileges" exception. That was quickly sorted by granting the required privilege to my user account.

On looking at ticket #17015 you pointed me to, it looks like I might have stumbled over the same issue as in the reply to ikelly. My user did not have the CREATE TRIGGER privilege the first time I tried to run syncdb, but did have the CREATE_TABLE and CREATE_SEQUENCE privileges. After granting the missing privilege and running syncdb again, I then got the ORA-01400 exception on table auth_permission.

I'm guessing that the first table that oracle back end base.py creates is auth_permission, and that the table and its primary key sequence were successfully created, because the user had the required privileges. Module base.py then terminated on attempting to create the trigger for the table. After granting CREATE TRIGGER and running syncdb again, base.py noted that table auth_permission exists, so nothing more needed to be done for that table. Module base.py then went on and created the remaining tables, sequences and triggers. Missing trigger auth_permission_tr -> no primary key raised from auth_permission_sq -> ORA-01400 on table auth_permission inserts.

Querying column timestamp of view user_objects for tables, sequences and triggers appears to confirm my understanding of what base.py does. I'll drop and recreate my user account, and try again. I'll advise how this goes. Does the Django doco have any specific documentation for the Oracle back end? If so, I missed it! I'm happy to provide specific doco for the Oracle back end if that would assist...

Once again, many thanks

Jon

Ian Kelly

unread,
Sep 1, 2012, 1:15:33 AM9/1/12
to django...@googlegroups.com
On Fri, Aug 31, 2012 at 10:03 PM, Jon Blake <jc.b...@gmail.com> wrote:
> Querying column timestamp of view user_objects for tables, sequences and
> triggers appears to confirm my understanding of what base.py does. I'll drop
> and recreate my user account, and try again. I'll advise how this goes. Does
> the Django doco have any specific documentation for the Oracle back end? If
> so, I missed it! I'm happy to provide specific doco for the Oracle back end
> if that would assist...

Yes, please see:

https://docs.djangoproject.com/en/1.4/ref/databases/#oracle-notes

Jon Blake

unread,
Sep 1, 2012, 1:42:50 AM9/1/12
to django...@googlegroups.com
I've just dropped and re-created my user account with required privileges, and all has gone as expected. Table auth_permission has 18 rows.

At the point where I'm prompted to create a superuser account, I made the mistake of resizing my terminal window, which resulted in exception EOFError being raised on the call to raw_input() in procedure create_superuser(). Sigh, and start again... This exception can be handled by calling raw_input() in a try block, and handling exception EOFError by (for example) shifting the cursor up one row by printing chr(27) +'[A' . HTH.

Again, many thanks. I'm on my way with Django - looking like a great framework!
  Jon

Jon Blake

unread,
Sep 1, 2012, 1:50:08 AM9/1/12
to django...@googlegroups.com
Thanks, Ian, I did miss that. Bookmarked for future reference.
Reply all
Reply to author
Forward
0 new messages