Django - DATABASES configuration

Asked

Viewed 43 times

0

DATABASES = { 'default': { 'ENGINE': 'sql_server.pyodbc', 'NAME': 'name',

The string of ODBC only use the attribute DATABASE, but Django only executes with the attribute NAME. How can I resolve this conflict? Grateful!

2 answers

0

Adriano, when you are setting up in Settings the database as illustrated by vc in the question, you are creating a dictionary that will represent key and value. If the DATABASE attribute is required you can put it as:

DATABASES = {
    'default': {
        'DATABASE_ENGINE': 'sql_server.pyobdc',
        'DATABASE_NAME': 'name',
        ...
    }
}

don’t forget to do pyobdc installation by not being native to Django

pip install sql_server.pyodbc
  • The installation of this version is 1.0 only gives support for SQL Server 2000 and 2005, use the 2017. I installed Pip install sql_server.pyodbc. For Django the NAME attribute is required, for ODBC it is necessary to use DATABASE. I put the DATABASE attribute in 'extra_params': 'DATABASE=XXX'. It didn’t work. Thanks!

  • I decided by putting: 'OPTIONS': { 'driver': 'ODBC Driver 17 for SQL Server', 'extra_params': 'SERVER=Name_server;Trusted_connection=Yes', },

  • there yes! adds a reply detailing the step by step to solve this problem... as was the Settings, the version q used, these details

0

Standard Django: DATABASES = { 'default': { 'ENGINE': 'sql_server.pyodbc', 'HOST': 'xxx', 'NAME': 'xxx', 'USER': 'xxx', 'PASSWORD': 'xxx', 'PORT': 'xxx', 'OPTIONS': { 'driver': 'ODBC Driver 17 for SQL Server', }, }, }

As ODBC did not recognize the NAME key and Django DATABASE. I added extra_params using the DATABASE key DATABASES = { 'default': { 'ENGINE': 'sql_server.pyodbc', 'HOST': 'xxx', 'NAME': 'xxx', 'USER': 'xxx', 'PASSWORD': 'xxx', 'PORT': 'xxx', 'OPTIONS': { 'driver': 'ODBC Driver 17 for SQL Server', 'extra_params': 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=xxx;DATABASE=xxx;USER=xxx;PASSWORD=xxx;Trusted_connection=Yes', }, }, }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.