I have the following model in Django:
class Event(models.Model):
# some fields
start_date = models.DateField()
end_date = models.DateField()
I'm using Oracle 10g Database with Django 1.5 and cx_oracle 5.1.2. The issue here is when I try to create a new object in the admin interface (picking dates from the calendar), the following error is raised:
ORA-01843: not a valid month
syncdb
has created a DATE
field in oracle for start_date
and end_date
. Does this look like a backend bug or am I doing something wrong?
I do have other models with DateTimeField()
and they work fine when I persist new objects, the issue looks related to DateField
itself.
UPDATE: I have checked the backend implementation, and in backends/oracle/base.py
lines 513 to 516:
cursor.execute(
"ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
" NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'"
+ (" TIME_ZONE = 'UTC'" if settings.USE_TZ else ''))
Executing this statement allows an insert statement to have literal values for DATE
fields. I have checked the query generated by the backend and it is inserting '2013-03-20'
in start_date
and end_date
. The date matches NLS_DATE_FORMAT
, so this in theory should work!
UPDATE: I believe my case is related to cx_oracle.
UPDATE: Since I still don't have a definite answer (although I'm almost sure it's cx_oracle that's causing this issue), I changed my DateField
into a DateTimeField
which translates into oracle's TIMESTAMP
and works perfectly fine.