2013-02-22 103 views
2

我目前正在運行Django 1.4.3,我想連接我自己的數據庫(在MongoLab中創建)與我的Django網站交談。我已經嘗試了以下有關如何實現此目的的大量教程;我在Django settings.py文件中遇到的問題是我的數據庫安裝不正確(由於無法連接)。我對Django和MongoDB非常新,所以任何幫助,將不勝感激。將Django連接到MongoLab數據庫

這裏是我跟着教程之一:http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released

注:我使用的是Mac和使用終端的一切,如果這個問題進行編程。

這裏是我的settings.py麻煩區域(大部分是由Django的自動生成)

DATABASES = { 
    'default': { 
     #'ENGINE': 'django_mongodb_engine', ### This wasn't working ### 
     'ENGINE': '', 
     'NAME': '',      # Or path to database file if using sq$ 
     'USER': '',      # Not used with sqlite3. 
     'PASSWORD': '',     # Not used with sqlite3. 
     'HOST': '',      # Set to empty string for localhost. N$ 
     'PORT': '',      # Set to empty string for default. Not$ 
    } 
} 

以下是錯誤消息:

Validating models... 

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10f732210>> 
Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run 
self.validate(display_num_errors=True) 
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate 
num_errors = get_validation_errors(s, app) 
    File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors 
from django.db import models, connection 
    File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module> 
backend = load_backend(connection.settings_dict['ENGINE']) 
    File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__ 
return getattr(connections[DEFAULT_DB_ALIAS], item) 
    File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__ 
backend = load_backend(db['ENGINE']) 
    File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend 
return import_module('.base', backend_name) 
    File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module 
__import__(name) 
    File "build/bdist.macosx-10.8-intel/egg/django_mongodb_engine/__init__.py", line 13, in <module> 
AttributeError: 'tuple' object has no attribute 'insert' 

文件:.../django_mongodb_engine/init .py(這是直接從下載,沒有編輯)

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

__version__ = (0, 4, 0) 
__author__ = "Flavio Percoco Premoli, Alberto Paro, " + \ 
     "Jonas Haag and contributors" 
__contact__ = "[email protected]" 
__homepage__ = "https://django-mongodb.org" 
__docformat__ = "restructuredtext" 

try: 
    from django.conf import settings 
    settings.INSTALLED_APPS.insert(0, 'django_mongodb_engine') 
    # It might be irritating that django-mongodb-engine registers itself as an app, 
    # and I think this is worth an explanation - so here you go: 
    # django-mongodb-engine provides a way to set MongoDB-specific options for a 
    # certain model via the 'MongoMeta' class/attribute (similar to the Django-style 
    # 'Meta' class). We want those options to be copied into the model's 
    # '_meta' object, right after the class has been defined. 
    # For this, we have to listen to the 'class_prepared' signal from 
    # 'django.db.models.signals'. Because the 'django_mongodb_engine' module gets 
    # imported as part of the initialization process of Django's ORM ('django.db'), 
    # we can *not* import anything from 'django.db' in this file (or any other 
    # submodule that is imported while the ORM initialization) because that would 
    # get us into recursive import hell which the Python interpreter doesn't allow. 
    # The only way to make sure certain code is executed after Django's ORM has been 
    # initialized is registering an app. After initializing itself, Django imports 
    # all apps defined in the project's 'settings.py' in the order implied by 
    # iterating over the INSTALLED_APPS list. As we have to make sure that 
    # django-mongodb-engine is loaded very first, we prepend it to the list. 
except ImportError: 
pass 
+0

你可以發佈你的settings.py和你的完整錯誤嗎? – dm03514 2013-02-22 21:33:32

+0

只是做,但它主要是自動生成的,從Django的 – 2013-02-22 21:40:47

+0

發佈錯誤信息,請 – 2013-02-22 21:56:31

回答

2

似乎是一個錯誤。

檢查this report

如果你跟隨鏈接,here開發商說:

MongoDB的發動機並不在這個時候支持的Django 1.4。所以堅持與 1.3。

這番話是記者從昨天。就這樣,您使用的Django版本不兼容。

2

您需要配置設置文件中的值。正如你所看到的,它們大部分是空的字符串。 MongoLab將爲您創建的數據庫提供主頁上所需的所有連接信息。

+0

我就拿出來,我有所有的正確的價值觀,我只是無法通過「django_mongodb_engine」連接。我不知道爲什麼它不會連接。 – 2013-02-22 21:45:03

+0

你可以發佈與堆棧跟蹤相關的錯誤消息嗎?(掩蓋所有密碼) – will 2013-02-22 22:05:23

+0

發佈了錯誤消息 – 2013-02-22 22:09:41