如何将Django连接到ibmcloud上的DB2数据库?

2024-04-25 11:43:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在云上使用Django和DB2创建一个简单的数据输入(CRUD)应用程序。问题是,我该怎么做?你知道吗

我开始试着跟着this tutorial。它不在云端,但这是我在Django与DB2的密切关系中发现的。根据我的直觉,我通过IBM云控制台在DB2上创建了一个凭证,并用以下内容填充settings.pyDATABASES变量:

DATABASES = {
    'default': {
        'ENGINE': 'ibm_db_django',
        'NAME': 'BLUDB',
        'USER': '*********',
        'PASSWORD': '***********',
        'HOST':'**********.services.<loc>.bluemix.net',
        'PORT': 5000,
        'PCONNECT' :  True,
    }
}

但是,在尝试运行python manage.py migrate之后,出现以下错误:

django.db.utils.Error: [IBM][CLI Driver] SQL1531N  The connection failed because the name specified 
with the DSN connection string keyword could not be found in either the db2dsdriver.cfg configuration file or the db2cli.ini configuration file.  Data source name specified in the connection string: "BLUDB". SQLCODE=-1531

老实说,我不知道发生了什么。但是在做了一点搜索之后,我在StackOverflow上发现了this post关于同样的问题。它没有真正明确的答案,但它把我引向this tutorial。基本上,我在INSTALLED_APPS列表中有几样东西:

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',
    'django_comments',
]

请注意,在我前面提到的教程中,我必须添加django.contrib.comments,而不是django_comments。但是基于the documentation,我必须添加django_comments' anddjango.contrib.sites公司. Then I tried to test it by runningPython管理.py测试`。测试过程中没有错误发生。你知道吗

但是,当我尝试运行“python管理.py迁移`再次,我仍然得到相同的错误。你知道吗

现在我还不确定到底发生了什么。我想知道是否有人能指出我遗漏了什么?提前谢谢。你知道吗


Tags: thedjangonamepydb错误connectionthis