Django models don't work with Oracle database









up vote
1
down vote

favorite












I have several apps with different database connections. They all work fine.
My new app needs an Oracle connection, which is set up in the settings.py:



'database_oracle' : 
'ENGINE' : 'oracle',
'NAME' : 'name',
'USER' : 'user',
'PASSWORD' : 'pw',
'HOST' : 'connection',
'PORT' : 1234,
'SCHMEA' : 'abc',
,


The models in my models.py have additional meta classes:



 class Meta:
db_table = '"abc.table1"'
data_source = 'database_oracle'
data_source_app = 'myapp'


The problem is that



Model1.objects.all() 


returns an error: `




django.db.utils.DatabaseError: ORA-00942: table or view does not exist




But if I use the django.db connection:



from django.db import connections
db_conn = connections['database_oracle']
c = db_conn.cursor()
c.execute("SELECT MAX(date) FROM abc.table1 WHERE key = 1234567").fetchall()


It works perfectly fine.
So I tried different spellings for db_table:



  1. db_table = 'table1'


  2. db_table = '"table1"'


  3. db_table = 'abc.table1'


  4. db_table = '"abc.table1"'


Changes were migrtated every time and this is how my routers.py look like (the if-statements belong to other apps and other databases):



myapps = ['myapp']
class DataRouter:
def db_for_read(self, model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def db_for_write(self,model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def allow_relation(self, obj1, obj2, **hints):
if [...]
elif obj1._meta.app_label in myapps or obj2._meta.app_label in myapps:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if [...]
elif app_label in myapps:
return db =='database_oracle'
return None


Does anyone have any idea why the models can't connect to my database?










share|improve this question























  • did you tried Model1.objects.using("database_oracle").all()?
    – dorintufar
    Nov 9 at 12:22






  • 1




    also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
    – dorintufar
    Nov 9 at 12:23











  • @dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
    – Andrea
    Nov 9 at 13:31






  • 1




    You've tried db_table = '"abc"."table1"'?
    – Will Keeling
    Nov 9 at 17:46










  • @WillKeeling that was the answer :). Thanks so much!
    – Andrea
    22 hours ago














up vote
1
down vote

favorite












I have several apps with different database connections. They all work fine.
My new app needs an Oracle connection, which is set up in the settings.py:



'database_oracle' : 
'ENGINE' : 'oracle',
'NAME' : 'name',
'USER' : 'user',
'PASSWORD' : 'pw',
'HOST' : 'connection',
'PORT' : 1234,
'SCHMEA' : 'abc',
,


The models in my models.py have additional meta classes:



 class Meta:
db_table = '"abc.table1"'
data_source = 'database_oracle'
data_source_app = 'myapp'


The problem is that



Model1.objects.all() 


returns an error: `




django.db.utils.DatabaseError: ORA-00942: table or view does not exist




But if I use the django.db connection:



from django.db import connections
db_conn = connections['database_oracle']
c = db_conn.cursor()
c.execute("SELECT MAX(date) FROM abc.table1 WHERE key = 1234567").fetchall()


It works perfectly fine.
So I tried different spellings for db_table:



  1. db_table = 'table1'


  2. db_table = '"table1"'


  3. db_table = 'abc.table1'


  4. db_table = '"abc.table1"'


Changes were migrtated every time and this is how my routers.py look like (the if-statements belong to other apps and other databases):



myapps = ['myapp']
class DataRouter:
def db_for_read(self, model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def db_for_write(self,model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def allow_relation(self, obj1, obj2, **hints):
if [...]
elif obj1._meta.app_label in myapps or obj2._meta.app_label in myapps:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if [...]
elif app_label in myapps:
return db =='database_oracle'
return None


Does anyone have any idea why the models can't connect to my database?










share|improve this question























  • did you tried Model1.objects.using("database_oracle").all()?
    – dorintufar
    Nov 9 at 12:22






  • 1




    also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
    – dorintufar
    Nov 9 at 12:23











  • @dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
    – Andrea
    Nov 9 at 13:31






  • 1




    You've tried db_table = '"abc"."table1"'?
    – Will Keeling
    Nov 9 at 17:46










  • @WillKeeling that was the answer :). Thanks so much!
    – Andrea
    22 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have several apps with different database connections. They all work fine.
My new app needs an Oracle connection, which is set up in the settings.py:



'database_oracle' : 
'ENGINE' : 'oracle',
'NAME' : 'name',
'USER' : 'user',
'PASSWORD' : 'pw',
'HOST' : 'connection',
'PORT' : 1234,
'SCHMEA' : 'abc',
,


The models in my models.py have additional meta classes:



 class Meta:
db_table = '"abc.table1"'
data_source = 'database_oracle'
data_source_app = 'myapp'


The problem is that



Model1.objects.all() 


returns an error: `




django.db.utils.DatabaseError: ORA-00942: table or view does not exist




But if I use the django.db connection:



from django.db import connections
db_conn = connections['database_oracle']
c = db_conn.cursor()
c.execute("SELECT MAX(date) FROM abc.table1 WHERE key = 1234567").fetchall()


It works perfectly fine.
So I tried different spellings for db_table:



  1. db_table = 'table1'


  2. db_table = '"table1"'


  3. db_table = 'abc.table1'


  4. db_table = '"abc.table1"'


Changes were migrtated every time and this is how my routers.py look like (the if-statements belong to other apps and other databases):



myapps = ['myapp']
class DataRouter:
def db_for_read(self, model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def db_for_write(self,model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def allow_relation(self, obj1, obj2, **hints):
if [...]
elif obj1._meta.app_label in myapps or obj2._meta.app_label in myapps:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if [...]
elif app_label in myapps:
return db =='database_oracle'
return None


Does anyone have any idea why the models can't connect to my database?










share|improve this question















I have several apps with different database connections. They all work fine.
My new app needs an Oracle connection, which is set up in the settings.py:



'database_oracle' : 
'ENGINE' : 'oracle',
'NAME' : 'name',
'USER' : 'user',
'PASSWORD' : 'pw',
'HOST' : 'connection',
'PORT' : 1234,
'SCHMEA' : 'abc',
,


The models in my models.py have additional meta classes:



 class Meta:
db_table = '"abc.table1"'
data_source = 'database_oracle'
data_source_app = 'myapp'


The problem is that



Model1.objects.all() 


returns an error: `




django.db.utils.DatabaseError: ORA-00942: table or view does not exist




But if I use the django.db connection:



from django.db import connections
db_conn = connections['database_oracle']
c = db_conn.cursor()
c.execute("SELECT MAX(date) FROM abc.table1 WHERE key = 1234567").fetchall()


It works perfectly fine.
So I tried different spellings for db_table:



  1. db_table = 'table1'


  2. db_table = '"table1"'


  3. db_table = 'abc.table1'


  4. db_table = '"abc.table1"'


Changes were migrtated every time and this is how my routers.py look like (the if-statements belong to other apps and other databases):



myapps = ['myapp']
class DataRouter:
def db_for_read(self, model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def db_for_write(self,model, **hints):
if [...]
elif model._meta.app_label in myapps:
return 'database_oracle'
return None
def allow_relation(self, obj1, obj2, **hints):
if [...]
elif obj1._meta.app_label in myapps or obj2._meta.app_label in myapps:
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if [...]
elif app_label in myapps:
return db =='database_oracle'
return None


Does anyone have any idea why the models can't connect to my database?







python django oracle django-models






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 12:22









Vineeth Sai

2,09231022




2,09231022










asked Nov 9 at 12:19









Andrea

152




152











  • did you tried Model1.objects.using("database_oracle").all()?
    – dorintufar
    Nov 9 at 12:22






  • 1




    also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
    – dorintufar
    Nov 9 at 12:23











  • @dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
    – Andrea
    Nov 9 at 13:31






  • 1




    You've tried db_table = '"abc"."table1"'?
    – Will Keeling
    Nov 9 at 17:46










  • @WillKeeling that was the answer :). Thanks so much!
    – Andrea
    22 hours ago
















  • did you tried Model1.objects.using("database_oracle").all()?
    – dorintufar
    Nov 9 at 12:22






  • 1




    also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
    – dorintufar
    Nov 9 at 12:23











  • @dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
    – Andrea
    Nov 9 at 13:31






  • 1




    You've tried db_table = '"abc"."table1"'?
    – Will Keeling
    Nov 9 at 17:46










  • @WillKeeling that was the answer :). Thanks so much!
    – Andrea
    22 hours ago















did you tried Model1.objects.using("database_oracle").all()?
– dorintufar
Nov 9 at 12:22




did you tried Model1.objects.using("database_oracle").all()?
– dorintufar
Nov 9 at 12:22




1




1




also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
– dorintufar
Nov 9 at 12:23





also try to remove unnecessary double quotes from db_table = '"abc.table1"' in Meta class
– dorintufar
Nov 9 at 12:23













@dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
– Andrea
Nov 9 at 13:31




@dorintufar thanks so far and yes, I tried it but the Traceback is still the same. And I tried the double quotes as Django suggests to use them for oracle dbs: docs.djangoproject.com/en/2.0/ref/models/options
– Andrea
Nov 9 at 13:31




1




1




You've tried db_table = '"abc"."table1"'?
– Will Keeling
Nov 9 at 17:46




You've tried db_table = '"abc"."table1"'?
– Will Keeling
Nov 9 at 17:46












@WillKeeling that was the answer :). Thanks so much!
– Andrea
22 hours ago




@WillKeeling that was the answer :). Thanks so much!
– Andrea
22 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225609%2fdjango-models-dont-work-with-oracle-database%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225609%2fdjango-models-dont-work-with-oracle-database%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo