Django-nonrel syncdb and mongodb: pymongo.errors.OperationFailure

I am using django-nonrel with mongodb-engine. I run the following error when running python manage.py syncdb:

Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 147, in handle_noargs index_sql = connection.creation.sql_indexes_for_model(model, self.style) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django_mongodb_engine/creation.py", line 49, in sql_indexes_for_model self._handle_oldstyle_indexes(ensure_index, meta) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django_mongodb_engine/creation.py", line 116, in _handle_oldstyle_indexes sparse=field.name in sparse_indexes) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/django_mongodb_engine/creation.py", line 42, in ensure_index return collection.ensure_index(*args, **kwargs) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/collection.py", line 1420, in ensure_index self.__create_index(keys, kwargs) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/collection.py", line 1298, in __create_index sock_info, cmd, read_preference=ReadPreference.PRIMARY) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/collection.py", line 208, in _command read_concern=read_concern) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/pool.py", line 239, in command read_concern) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/network.py", line 102, in command helpers._check_command_response(response_doc, None, allowable_errors) File "/Users/<user>/site/qmcdb/lib/python2.7/site-packages/pymongo/helpers.py", line 205, in _check_command_response raise OperationFailure(msg % errmsg, code, response) pymongo.errors.OperationFailure: The field 'sparse' is not valid for an _id index specification. Specification: { ns: "qmcdb_mongodb.django_admin_log", v: 2, sparse: false, unique: true, name: "_id_1", key: { _id: 1 } } 

I do not know what happened. I tried to get mongodb to work with django and I had a lot of problems. My settings.py:

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

Hope I posted enough background information. I would really appreciate any help.

+7
python mongodb django-nonrel
source share
4 answers

Try using Mongo database in version 3.2, there is some problem with mongoengine and Mongo Server 3.4

+4
source share

1.Used by syncdb in version 3.2 of MongoDB 3.4, it still causes an error.

2. In MongoDB 2.6, syncdb works fine with a minor unrelated problem. I still have a bug in version 2.6 and fixed it ( https://gist.github.com/ielshareef/2986459 ).

3.django_mongodb_engine is a buggy that has been forked from django1.3. Also, this repo is out of date that the last commit was July 13, 2015. I should not recommend this package.

4. I would recommend https://github.com/MongoEngine/django-mongoengine

+2
source share

My hacked solution for this was changing lines 115-116 from Lib\site-packages\django_mongodb_engine\creation.py from this:

 ensure_index(column, unique=field.unique, sparse=field.name in sparse_indexes) 

:

 ensure_index(column) 

It seems like I'm wrong, but I'm sure something will happen catastrophically somewhere because I have no idea what I'm doing.

I will also wait for an answer.

0
source share

I recommend you use:

 pip3 install git+https://github.com/MongoEngine/django-mongoengine Django 1.11.2 Python 3.6 MongoDB 3.4 

Always good, use updated versions of packages, use isolation of the environment. https://virtualenvwrapper.readthedocs.io/en/latest/install.html

0
source share

All Articles