django-nonrel syncdb and mongodb: pymongo.errors.OperationFailure - python

I am using django-nonrel with mongodb-engine I am getting the following error when I run 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 have no idea what is wrong. I've been trying to get mongodb to work with django and I have been having a lot of issues. My settings.py:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'qmcdb_mongodb',
'PORT': 27017,
'HOST': 'localhost'
}
}
I hope I have posted enough background information. I would really appreciate any help.

Try use Mongo database in version 3.2, There is some problem with mongoengine and Mongo Server 3.4

1.Tested syncdb in MongoDB version 3.2 3.4, it still raising error.
2.In the MongoDB 2.6 syncdb is running fine with a minor unrelated problem.I still got an error in version 2.6 and fixed with this(https://gist.github.com/ielshareef/2986459).
3.django_mongodb_engine is so buggy which was forked from django1.3 . Also, this repo is outdated that last commit was on Jul 13, 2015. I should not recommend this package.
4.I would recommend https://github.com/MongoEngine/django-mongoengine

My hacky solution to this was modifying lines 115-116 of Lib\site-packages\django_mongodb_engine\creation.py
from this:
ensure_index(column, unique=field.unique,
sparse=field.name in sparse_indexes)
to this:
ensure_index(column)
It seems to clear the error, but I'm sure it's gonna make something somewhere fail catastrophically because I have no idea what I'm doing.
I'll be waiting on a better answer too.

I recommend you use:
pip3 install git+https://github.com/MongoEngine/django-mongoengine
Django 1.11.2
Python 3.6
MongoDB 3.4
Always is good, use versions updated of packages, use isolation of environment.
https://virtualenvwrapper.readthedocs.io/en/latest/install.html

Related

Unable to set up Elasticsearch for Wagtail

I used the following guide so far:
http://docs.wagtail.io/en/v1.9/advanced_topics/performance.html
I added:
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch',
'INDEX': '{{ project_name }}',
},
}
to my base.py. When I run $ ./manage.py update_index, I get the following output:
Updating backend: default
default: Rebuilding index {{ project_name }}
Traceback (most recent call last):
File "./manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 120, in handle
self.update_backend(backend_name, schema_only=options.get('schema_only', False))
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 73, in update_backend
index = rebuilder.start()
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 613, in start
self.reset_index()
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 609, in reset_index
self.index.reset()
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 598, in reset
self.delete()
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 499, in delete
self.es.indices.delete(self.name)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 73, in _wrapped
return func(*args, params=params, **kwargs)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/client/indices.py", line 200, in delete
params=params)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 318, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/home/emtr0/Env/emtr0dotcom/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 123, in perform_request
raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f3b708fa210>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f3b708fa210>: Failed to establish a new connection: [Errno 111] Connection refused)
Thanks in advance.
EDIT UPDATE:
It looks like my Linode might not have enough RAM. I get the following error when trying to run ES with ./bin/elasticsearch after global install:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/emtr0/elasticsearch-5.3.0/hs_err_pid24719.log
Thanks.
For people still having issues with this, make sure your Elasticsearch version and elasticsearch-py version are the same. Both elasticsearch and the py versions need to be installed. That fixed it for me.
sorry I don't have enough reputation to comment directly under your question, I hope this will help you to get things sorted out:
install elasticsearch locally, run it, and then check if it's running (should be on port 9200) using a simple curl http://localhost:9200. If you get a JSON response, it's running 🎉
OR
setup a bonsai (http://bonsai.io) instance in order to have a hosted elasticsearch server running, and just copy-paste the bonsai's server URL into your config, but it can need a bit more settings (SSL etc), and is more limited in term of elasticsearch version
Bonus: if you are a macOS user, installing/running Elastic Search is as easy as brew install elasticsearch (maybe set a specific version though), and then elasticsearch if you don't mind about having it running in the foreground.

django 1.10.3 Cannot resolve bases after flush

I have a playground for model developement.
When running python manage.py makemigrations the Error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 173, in handle
migration_name=self.migration_name,
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 47, in changes
changes = self._detect_changes(convert_apps, graph)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 132, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 180, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 242, in __init__
self.render_multiple(list(models.values()) + self.real_models)
File "/home/IPP-HGW/dboe/anaconda2/lib/python2.7/site-packages/django/db/migrations/state.py", line 285, in render_multiple
"for more" % (new_unrendered_models, get_docs_version())
django.db.migrations.exceptions.InvalidBasesError: Cannot resolve bases for [<ModelState: 'main.Component'>, <ModelState: 'main.MagneticConfig'>, <ModelState: 'main.NetStructure'>, <ModelState: 'main.Program'>, <ModelState: 'main.FilePath'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.10/topics/migrations/#dependencies for more
Keeps occuring though i tried a hell of a lot:
of course python manage.py makemigration <appName>
python manage.py migrate <appName>
drop all tables from the app
python manage.py squashmigrations main 0001
emptied the models.py file
uncommented the app in settings
read everything i could find on that
flushing the whole database python manage.py flush
Any idea, how to solve this? Thanks,
Daniel
Edit Nov_29:
Stack trace added
Finally i got the solution. I found out, that the migrations are stored in a file in the application folder. You can delete these by hand. Of course, you need to be very careful with this.
Take a look at this if you got the same problem.

Setting Up Apache Solr on Local Instance of readthedocs.org

Link to Instructions
I am following the instructions at http://read-the-docs.readthedocs.org/en/latest/install.html#solr-search-setup
Question
Currently, I am able to set up a local instance of readthedocs.org; however, I cannot set up search correctly on it as I can't seem to generate the necessary schema.xml file by running the following command. The context of which is in the link above.
./manage.py build_solr_schema > $SOLR_PATH/solr/conf/schema.xml
Instead of successfully generating a schema.xml, I am presented with this error.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/***/ford-env/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 26, in handle
schema_xml = self.build_template(using=using)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 52, in build_template
c = self.build_context(using=using)
File "/home/***/ford-env/local/lib/python2.7/site-packages/haystack/management/commands/build_solr_schema.py", line 38, in build_context
raise ImproperlyConfigured("'%s' isn't configured as a SolrEngine)." % backend.connection_alias)
I'm guessing there is an extra step involving for configuring solr with django before generating xml. Similar errors suggest editing a settings.py file, but I cannot seem to find one within the project directory. Due to my lack of familiarity with django, I don't know how to continue from here.
you have to update the settings files in readthedocs.org/readthedocs/settings/*.py and update the HAYSTACK_CONNECTIONS dict with (if you're using solr):
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr',
}
}
check init.py, base.py, sqlite.py. Then it worked perfectly.

Trouble connecting to MS SQL Server with django-mssql

I'm trying to use django-mssql to connect to MS SQL Server 2008 R2 with Django 1.4.2 These are my Database settings:
DATABASE_ENGINE = 'sqlserver_ado'
DATABASE_NAME = 'dbtest'
DATABASE_USER = 'App'
DATABASE_PASSWORD = '*********'
DATABASE_HOST = 'localhost'
DATABASE_OPTIONS = {
'provider': 'SQLNCLI10',
'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
}
DATABASES = {
'default': {
'ENGINE': DATABASE_ENGINE,
'NAME': DATABASE_NAME,
'USER': DATABASE_USER,
'PASSWORD': DATABASE_PASSWORD,
'HOST': DATABASE_HOST,
'OPTIONS' : DATABASE_OPTIONS,
},
}
This is the error I get when I try to syncdb
Traceback (most recent call last):
File "C:\Python27\DataSatellite\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 193, in _cursor
self.__connect()
File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 168, in __connect
use_transactions=self.use_transactions,
File "C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py", line 151, in connect
raise OperationalError(e, "Error opening connection: " + connection_string)
sqlserver_ado.dbapi.OperationalError: (AttributeError("'module' object has no attribute 'VARIANT'",), 'Error opening connection: DATA SOURCE=localhost;Initial Catalog=dbtest;UID=App;PWD=*********;PROVIDER=SQLNCLI10;MARS Connection=True;DataTypeCompatibility=80;MARS Connection=True;')
Finished "C:\Python27\DataSatellite\manage.py syncdb" execution.
I've looked everywhere and I cannot seem to understand and fix the problem. I hope someone can help!
Thanks!
Edit:
I've already created the database. I've also connected to the database using django-pyodbc, and I've successfully read and written from the database. But django-pyodbc causes problems when I use Apache, which was why I decided to try django-mssql. However, I do not understand the error it comes up with.
My Django (1.4.2) and Python (2.7) installs run on Windows, and I'm using an Apache webserver.
Update pywin32 to build 217 or greater. I found another question on stackoverflow with the same issue (on another topic):
Python COM server throws 'module' object has no attribute 'VARIANT'

Any idea why i am getting this error?

I am trying to install django-cms in my ubuntu pc. I am getting this error:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.6/dist-packages/cms/__init__.py", line 14, in <module>
patch_settings()
File "/usr/local/lib/python2.6/dist-packages/cms/conf/__init__.py", line 32, in patch_settings
post_patch()
File "/usr/local/lib/python2.6/dist-packages/cms/conf/patch.py", line 26, in post_patch
settings.CMS_TEMPLATES = tuple(settings.CMS_TEMPLATES) + (
TypeError: 'NoneType' object is not iterable
Any idea why is this error coming?
thanks
Edit -1 --
HI guys,
Yes you were rightm i didnt put cms_templates in settings.py. I did it now, but now I am getting this error.
DatabaseError at /
no such table: cms_page
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: DatabaseError
Exception Value:
no such table: cms_page
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py in execute, line 234
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Fri, 25 Mar 2011 15:34:04 -0500
It's looking for a settings.CMS_TEMPLATES. It's trying to make None a tuple which would throw that error.
Make sure you have a CMS_TEMPLATES defined.
http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html#configuration-and-setup
Your CMS_TEMPLATES settings is None, I have no idea what that is, but I'm guessing it a setting you need to configure somewhere.
settings.CMS_TEMPLATES is None, I believe. It's hard to tell without a sample of the code in question.
Referring to edit 1:
Which commands are you using? Are you following the tutorial? I guess you did not do:
python manage.py syncdb
If you just wrote your models, this command will create the tables in the db. Otherwise the database is empty, which is the reason why Django can't find the cms_pagetable.

Categories