Problems connecting to an oracle legacy db

73 views
Skip to first unread message

Vittorio

unread,
Jun 4, 2014, 4:38:34 AM6/4/14
to django...@googlegroups.com
I have an Ubuntu linux server on which I installed the oracle instanclient stuff to run a client of a remote legacy oracle database.

It works great!

#TNSNAMES.ORA
my_db=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 46.128.3.178)(PORT = 1521))
)
(CONNECT_DATA =
(SID = DANT)
)
)

Trying with SQLPlus

victor@ubuntu:~$ sqlplus my_user/my_passw@my_db
SQL*Plus: Release 12.1.0.1.0 Production on Wed Jun 4 09:57:04 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved

Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL>

... and with Python

>>> import cx_Oracle
>>> con = cx_Oracle.connect('my_user', 'my_passw', '46.128.3.178:/DANT')
>>> cur = con.cursor()
>>> cur.execute('select * from noema.magazzino_vista_lista')
<cx_Oracle.Cursor on <cx_Oracle.Connection to my_...@46.128.3.178:/DANT>>
>>>
>>> for result in cur:
... print result
...
(12, 'MAG0005240', '0005240', 1)
(12, 'MAG0000946', '0000946', 2)
(12, 'MAG0001930', '0001930', 3)
(17, 'MAGCARPIE008', 'CARPIE008', 1)
(17, 'MAGLETTEL0002', 'LETTEL0002', 1)
>>>

That's all ok!

Now, on the same server, I have a django 1.6.2 project named 'myorac' and an application called 'noematica'

#settings.py
......
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'my_db',
'USER': 'my_user',
'PASSWORD': 'my_passw',
'HOST': '46.128.3.178',
'PORT': '1521',
},
}

#models.py
...........
class magazzino_vista_lista(models.Model):
id_ordine = models.IntegerField(null=False, blank=False, db_column='ID_ORDINE')
cod_magazzino_galileo = models.CharField(max_length=48, db_column='COD_MAGAZZINO_GALILEO')
cod_magazzino_ext = models.CharField(max_length=48, db_column='COD_MAGAZZINO_EXT')
qta = models.IntegerField(null=False, blank=False, db_column='QTA')
class Meta:
managed = False
db_table = u'noema.magazzino_vista_lista'
verbose_name_plural = "CC specifica ordini vista"

***** See the real oracle table is named 'noema.magazzino_vista_lista' as in the sql I called before under python *****

#admin.py
.....
admin.site.register(magazzino_vista_lista)


When I start my application via python manage.py runserver I get the following error in the browser at the very beginning

DatabaseError at /noematica/
ORA-00942: table or view does not exist
Request Method: GET
Request URL: http://10.20.0.1:7600/noematica/
Django Version: 1.6.2
Exception Type: DatabaseError
Exception Value:
ORA-00942: table or view does not exist
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/oracle/base.py in execute, line 815


Why is that? I can't figure out what I made it wrong in the definition of the database in settings.py or in the db_table definition in models.py
Please help
Vittorio

Ian

unread,
Jun 4, 2014, 12:07:01 PM6/4/14
to django...@googlegroups.com, ml-...@de-martino.it
On Wednesday, June 4, 2014 2:38:34 AM UTC-6, Vittorio wrote:
#models.py
...........
class magazzino_vista_lista(models.Model):
    id_ordine = models.IntegerField(null=False, blank=False, db_column='ID_ORDINE')
    cod_magazzino_galileo = models.CharField(max_length=48, db_column='COD_MAGAZZINO_GALILEO')
    cod_magazzino_ext = models.CharField(max_length=48, db_column='COD_MAGAZZINO_EXT')
    qta = models.IntegerField(null=False, blank=False, db_column='QTA')
    class Meta:
        managed = False
        db_table = u'noema.magazzino_vista_lista'
        verbose_name_plural = "CC specifica ordini vista"

***** See the real oracle table is named 'noema.magazzino_vista_lista' as in the sql I called before under python *****


Django currently doesn't understand schemas, and it quotes and treats the "noema." as being part of the table name rather than a schema. There's a hacky way (which basically amounts to SQL injection by the developer) to make it quote the schema and table separately, but I recommend creating synonyms to your tables in the schema that Django actually connects to.
Reply all
Reply to author
Forward
0 new messages