Django oracle db settings

孤人 提交于 2019-12-02 11:46:08

You should change HOST to localhost' or '127.0.0.1 and SID is NAME.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'xe',
        'USER': 'system',
        'PASSWORD': 'oracle',        
        'HOST':'127.0.0.1',
        'PORT':'1521'
    }
}

For future references, if Oracle is configured with Service name instead of SID, then the configuration would be:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': '127.0.0.1:1521/service.name',
        'USER': 'system',
        'PASSWORD': 'oracle',        
    }
}

Another thing to consider when working with Oracle in Django is that when you connect to Other Users (schema) database, you have to set db_table Meta option in Django models:

class OracleTable(models.Model):
    ... fields ...
    class Meta:
        db_table = '\"OTHERUSER\".\"ORACLETABLE\"'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!