且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django连接到IBM Cloud数据库

更新时间:2022-06-26 09:39:54

使用以下版本,我可以连接python + django + ibm_db_django + Db2-on-cloud.

With the versions below, I can connect python + django + ibm_db_django + Db2-on-cloud .

运行 python manage.py migration 表示与Db2-on-cloud的连接成功.

Running python manage.py migrate shows that the connection to Db2-on-cloud is succeeding.

根据版本,如果缺少特定的数据库权限, python manage.py migration 可能会因Db2-on-cloud精简版"(免费)计划而失败.

Depending on versions, the python manage.py migrate might fail with the Db2-on-cloud 'lite' (free) plan, if specific database permissions are missing.

要在成功运行 manage.py migration 后进一步使用django,请在 djangoproject.com 上遵循您的django版本的在线教程.

To work further with django after running the manage.py migrate successfully, please follow the online tutorial for your version of django at djangoproject.com .

我尝试了以下版本(2020年2月):

I tried these versions (february 2020):

python          3.6.9  x64
pip             20.0.2
django          2.2.5
ibm_db          3.0.1
ibm_db_django   1.2.0.0a0  (lower versions always failed).

注意:其他组合也可能有效,您的里程可能会有所不同.

Note: other combinations might work, your mileage may vary.

我对 ibm_db_dbi.py 进行了修补,以解决github上详述的开放缺陷( https://github.com/ibmdb/python-ibmdb-django/issues/44 )(感谢trebor74hr)

I patched the ibm_db_dbi.py to workaround an open defect as detailed on github (https://github.com/ibmdb/python-ibmdb-django/issues/44) (thanks to trebor74hr )

要使 manage.py迁移步骤正常工作,我所做的三个 settings.py 更改是:

To get the manage.py migrate step working, the three settings.py changes I made were:

(1)安装的应用程序可能会因您的版本和应用程序而异.

(1) The installed apps may vary with your versions and your app.

  INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    'django.contrib.redirects',
    'django.contrib.sites',

]

(2)

DATABASES = {
  'default': {
  'ENGINE'   : 'ibm_db_django',
  'NAME'     : 'bludb',
  'USER'     : '......',
  'PASSWORD' : '...............',
  'HOST'     : 'dashdb-txn-sbox-............services....bluemix.net',
  'PORT'     : '50000',
  'PCONNECT' :  True,      #Optional property. It is true by default
  }
}

(3)

#USE_TZ = True
   (or remove the line, the # makes it a comment ).