Django的db2驱动程序? [英] Db2 driver for Django?

查看:281
本文介绍了Django的db2驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,Django当前仅提供4个后端数据库引擎:

It seems to me that Django currenty only provides 4 backend database engine which are:


  1. 'django.db.backends.postgresql'

  2. 'django.db.backends.mysql'

  3. 'django.db.backends.sqlite3'

  4. 'django.db.backends.oracle'

  1. 'django.db.backends.postgresql'
  2. 'django.db.backends.mysql'
  3. 'django.db.backends.sqlite3'
  4. 'django.db.backends.oracle'

如果我使用MySQL,我要做的就是填充 Engine 'django.db.backends.mysql'。但是现在,因为我的主要数据库是DB2,所以在将它与pyodbc连接时遇到了一些问题。

If I use MySQL, all I have to do is just fill the Engine with 'django.db.backends.mysql'. But now, because my main Database is DB2, I'm having some issues to connect it with pyodbc. What is needed?

import os

SECRET_KEY = 'o0zdmzzdw44tkd5a7o*h-@*bo)r@f#)!)$)8f-y%=sn*kr)@t%'

DEBUG = True

ALLOWED_HOSTS = [127.0.0.1]

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'arapi.apps.ArapiConfig', #my projeck
    'rest-framework', 
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'arDRFAPIWEB.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'arDRFAPIWEB.wsgi.application'

DATABASES = {
      'default': {
          'ENGINE': 'ibm_db_django',
          'NAME': as400,
          'USER' : root,
          'PASSWORD' : root,
          'HOST' : as400.****.co.id,
          'PORT' : 3306,
          'PCONNECT'   :  True, #Optional property, default is false
      }
   }

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

当我运行 python manage.py test 时出现此错误


尝试使用'django.db.backends.XXX',其中XXX是以下之一:
'mysql','oracle','postgresql','sqlite3'

Try using 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3'

虽然我已经降级了将 python转换为3.6.5 版本,而我的 django是2.1.1 版本,我认为这可以解决问题。

Although I've downgrade the python into 3.6.5 version and my django is 2.1.1 version which I thought this might solve the problem.

推荐答案

有一个适用于IBM Db2的Django驱动程序。它甚至是在Db2文档中引用了,并且有一个文档描述了 Db2和Django的设置过程。在那里,他们建议这样的配置:

There is a Django driver available for IBM Db2. It is even referenced in the Db2 documentation and there is a document which describes the setup procedure for Db2 and Django. There, they suggest a configuration like this:

DATABASES = {
  'default': {
  'ENGINE'   : 'ibm_db_django',
  'NAME'     : 'database',
  'USER'     : 'user',
  'PASSWORD' : 'password',
  'HOST'     : 'localhost',
  'PORT'     : '50000',
  'PCONNECT' :  True,      #Optional property. It is true by default
  }
}

您可以找到驱动程序<

You can find the driver package ibm_db_django in the related GitHub repo.

您需要指定 ibm_db_django ,而不是例如 django.db.backends.mysql django.db.backends.db2 会给出错误。

You need to specify ibm_db_django instead of, e.g., django.db.backends.mysql. django.db.backends.db2 will give an error.

这篇关于Django的db2驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆