Reputation: 85
I'm new in Django. I'm trying to connect Django app to IBM Cloud db, I loaded my data IBM cloud and created credionals.
Then installed ibm_db_django
$ easy_install ibm_db_django
Then in setting.py did import
import ibm_db_django
Then I added credionals in settings.py
DATABASES = {
'default': {
'ENGINE' : 'ibm_db_django',
'NAME' : 'BLUDB',
'USER' : 'USER',
'PASSWORD' : 'PASSWORD',
'HOST' : 'dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net',
'PORT' : '50000',
'PROTOCOL' : 'TCPIP',
'PCONNECT' : True,
},
}
Otput of python manage.py test django.contrib.auth
:
System check identified no issues (0 silenced).
Is this enough to connect to ibm cloud db? Now how can I test is this connected to database, and how can I generate models from database?
Upvotes: 0
Views: 860
Reputation: 12267
With the versions below, I can connect python + django + ibm_db_django + Db2-on-cloud .
Running python manage.py migrate
shows that the connection to Db2-on-cloud is succeeding.
Depending on versions, the python manage.py migrate
might fail with the Db2-on-cloud 'lite' (free) plan, if specific database permissions are missing.
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
.
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.
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 )
To get the manage.py migrate
step working, the three settings.py
changes I made were:
(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 ).
Upvotes: 1