2

我正在尝试Mongodb在我的Django.

下面有连接设置settings.py

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)


MANAGERS = ADMINS



DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine', 
        'NAME': '',                      
        'USER': '',                      
        'PASSWORD': '',                  
        'HOST': 'localhost',                      
        'PORT': 27017,                      
    }
}

当我尝试运行python manage.py syncdb时,出现如下错误:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 59, in handle_noargs
    tables = connection.introspection.table_names()
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 76, in table_names
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 106, in __getattr__
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 133, in _connect
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1025, in __getitem__
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1014, in __getattr__
  File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/database.py", line 74, in __init__

django.core.exceptions.ImproperlyConfigured: name must be an instance of basestring

我正在使用 django 1.3

提前致谢

4

1 回答 1

6

我从未将 mongodb 与 django 一起使用,但我会通过跟踪跟踪来尝试一下。您需要为NAME数据库配置中的设置添加一个值

DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine', 
        'NAME': 'foobar',                      
        'USER': '',                      
        'PASSWORD': '',                  
        'HOST': 'localhost',                      
        'PORT': 27017,                      
    }
}

错误在这里pymongo被抛出,在这里通过django_mongo_engine

于 2013-03-14T08:57:50.653 回答