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'
Related
i think below setting will work for the djongo to connect to the remote mongodb on mongodb.com but, the error message shows its still trying to connect to the localhost
DATABASES = {
'default': {
'ENGINE': 'djongo',
'HOST': 'mongodb+srv://<username>:<password>#cluster-name/<dbname>?retryWrites=true&w=majority',
}
below is the error traceback
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
self.check_migrations()
File "venv/lib/python3.6/site-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "venv/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
return get_names(cursor)
File "venv/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "venv/lib/python3.6/site-packages/djongo/introspection.py", line 47, in get_table_list
for c in cursor.db_conn.list_collection_names()
File "venv/lib/python3.6/site-packages/pymongo/database.py", line 856, in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
File "venv/lib/python3.6/site-packages/pymongo/database.py", line 819, in list_collections
_cmd, read_pref, session)
File "venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1454, in _retryable_read
read_pref, session, address=address)
File "venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1253, in _select_server
server = topology.select_server(server_selector)
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 235, in select_server
address))
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 193, in select_servers
selector, server_timeout, address)
File "venv/lib/python3.6/site-packages/pymongo/topology.py", line 209, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
I have met your problem before. In my case, I run django & mongodb inside containers. And I found that whatever setting I set inside setting.py, the djongo(they use pymongo behind) just ignore my setting.
For others seeking for the solution, you may want to check your syntax in setting.py which should look like below:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
'ENFORCE_SCHEMA': False,
'CLIENT': {
'host': 'host-name or ip address',
'port': port_number,
'username': 'db-username',
'password': 'password',
'authSource': 'db-name',
'authMechanism': 'SCRAM-SHA-1'
},
.......
}
Detail from djongo document
You can see the host, user, password fields are all under 'CLIENT' , which is different with the default syntax described by Django. So maybe most people get confused here and stuck at this problem.
Go to settings.py file and use below Database settngs
DATABASES = {
'default': {
'ENGINE': 'djongo',
'ENFORCE_SCHEMA': True
'NAME': 'your-db-name',
'HOST': 'host-name or ip address',
'PORT': port_number,
'USER': 'db-username',
'PASSWORD': 'password',
'AUTH_SOURCE': 'db-name',
'AUTH_MECHANISM': 'SCRAM-SHA-1',
}
Please also check out this article for connection between django and mongo db.
https://medium.com/#ksarthak4ever/how-to-use-django-with-mongodb-40ba36a21124
I personally recommend you please use pycharm. In Pycharm you can test your connection. So that you can get more clear image of whole scenario.
I use remote database in django. you can see in the below picture
I GOT THE SOLUTION
I adopted following approach >
so, behind the scene the djongo uses -> pymongo
and pymongo's default configuration are
class MongoClient(common.BaseObject):
HOST = "localhost" # here HOST has the hardcoded value
PORT = 27017
which lies in following file
venv/lib/python3.6/site-packages/pymongo/mongo_client.py
replace the harcoded value of HOST to something like
HOST = 'mongodb+srv://<username>:<password>#cluster-name/<dbname>?retryWrites=true&w=majority'
ADDITIONALLY
We can set the environment variable if we want
HOST = os.getenv('MONGO_DB_URL')
Edit skip first part, I found out (well, they tell me) that the problem is in the database \edit
I Have a python+django project that I keep on two computers. I mean have two copy of the same project and sometimes I work on one, sometimes on the other. With copy-paste I lose the secret key in a settings.py (they were different but I overwrite). I don't know how generation and storage of secret keys works but to recover I start a new project, took the key and copied the files like this:
1) make a copy of the project
2) deleted the original project but kept the copy
3) started a new project with the same name (so, in the same folder like the original)
4) copied the new secret key
5) copied the files from the copy of the old project in the new project (so settings.py is lost and the new secret key with it, but I have a copy)
6) changed the secret key with the new secret key
But this don't works and it gives the same error like before:
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x0000000004ADAEA0>
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATALE: autenticazione con password fallita per l'ut
ente "gm"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\utils\autorelo
ad.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\base.py", line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 61, in applied_migrations
if self.has_table():
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_
names(self.connection.cursor())
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 255, in cursor
return self._cursor()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 232, in _cursor
self.ensure_connection()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\utils.py",
line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATALE: autenticazione con password fallita p
er l'utente "gm"
translated: authentication with password failed for user 'gm'
I'm not sure when it happened the first time but I have another problem, probabily linked: I can't access the database. Maybe this is the cause of the first problem and not the secret key.
I use PostgreSQL and I access it using the utility standard pgAdmin III. It gives me the initial screen with Servers: PostgreSQL 9.5, I right click on it and select connect, it ask me for password, I gives but it throws an error:
An error has occurred. Error connecting to the server: FATALE: autenticazione con password fallita per l'utente 'postgres'.
translated: authentication with password failed for user 'postgres'
I have created only one database and user so I have the standard postgres and my database 'possedimenti_db' with an user called 'gm'.
What can I do? I don't mind the data present, I can delete all but if it don't make me access I don't know how to delete.
Thank you
My settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'possedimenti_db',
'USER': 'gm',
'PASSWORD': database_key,
'HOST': host_key,
'PORT': '5432',
}
}
database_key and host_key are imported from external file.
Also database_key is different from the password I use to access the database with pgAdmin. In my other pc it works. I tried to change it in the other password but it throws anyway the same error.
Edit
You Can read the solution in the comments of the answer but the problem was that my user hadn't a password definited.
Use 'django.db.backends.postgresql_psycopg2' instead of 'django.db.backends.postgresql'.
you have to install psycopg2. Use this command:
pip install psycopg2
Here is the example:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'team_db',
'USER': 'jason',
'PASSWORD': 'abcd',
'HOST': 'localhost',
'PORT': '5432',
}
}
I have a Django app with a worker process which does database transactions. Under the hood, I have an Azure SQL database attached to my application. The worker code looks something like this:
class Command(BaseCommand):
def handle(self, *args, **kwargs):
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
consumer = Consumer()
logging.info('Booting drive consumer')
while True:
messages = consumer.poll()
for message in messages:
...
DriveEvent.objects.create(event_id=response['Id'], drive_id=drive_payload['drive_id'])
...
After about 20 mins, the create db object calls start failing with the following error:
[drive-consumer-1]2017-07-19T03:19:08.545128400Z Traceback (most recent call last):
[drive-consumer-1]2017-07-19T03:19:08.545133000Z File "/code/miles/management/commands/drive_consumer_worker.py", line 28, in handle
[drive-consumer-1]2017-07-19T03:19:08.545137900Z drive_consumer.consume(json.loads(record.value))
[drive-consumer-1]2017-07-19T03:19:08.545142500Z File "/code/miles/workers/drive_consumer.py", line 35, in consume
[drive-consumer-1]2017-07-19T03:19:08.545152200Z self._on_create(message['calendar_id'], drive_payload, message['access_token'])
[drive-consumer-1]2017-07-19T03:19:08.545156900Z File "/code/miles/workers/drive_consumer.py", line 46, in _on_create
[drive-consumer-1]2017-07-19T03:19:08.545161500Z DriveEvent.objects.create(event_id=response['Id'], drive_id=drive_payload['drive_id'])
[drive-consumer-1]2017-07-19T03:19:08.545166500Z File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
[drive-consumer-1]2017-07-19T03:19:08.545171300Z return getattr(self.get_queryset(), name)(*args, **kwargs)
[drive-consumer-1]2017-07-19T03:19:08.545175900Z File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 399, in create
[drive-consumer-1]2017-07-19T03:19:08.545180700Z obj.save(force_insert=True, using=self.db)
[drive-consumer-1]2017-07-19T03:19:08.545185400Z File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
[drive-consumer-1]2017-07-19T03:19:08.545190200Z force_update=force_update, update_fields=update_fields)
[drive-consumer-1]2017-07-19T03:19:08.545194800Z File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 821, in save_base
[drive-consumer-1]2017-07-19T03:19:08.545211400Z with transaction.atomic(using=using, savepoint=False):
[drive-consumer-1]2017-07-19T03:19:08.545215800Z File "/usr/local/lib/python2.7/site-packages/django/db/transaction.py", line 184, in __enter__
[drive-consumer-1]2017-07-19T03:19:08.545220400Z connection.set_autocommit(False, force_begin_transaction_with_broken_autocommit=True)
[drive-consumer-1]2017-07-19T03:19:08.545224900Z File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 391, in set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545229600Z self._set_autocommit(autocommit)
[drive-consumer-1]2017-07-19T03:19:08.545234000Z File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 453, in _set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545238600Z self.connection.autocommit = autocommit
[drive-consumer-1]2017-07-19T03:19:08.545243100Z File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
[drive-consumer-1]2017-07-19T03:19:08.545247700Z six.reraise(dj_exc_type, dj_exc_value, traceback)
[drive-consumer-1]2017-07-19T03:19:08.545252200Z File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 453, in _set_autocommit
[drive-consumer-1]2017-07-19T03:19:08.545256800Z self.connection.autocommit = autocommit
[drive-consumer-1]2017-07-19T03:19:08.545262600Z Error: ('08S01', '[08S01] [FreeTDS][SQL Server]Write to the server failed (20006) (SQLSetConnectAttr)')
Database init (in settings.py) looks something like this:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': os.environ.get('DB_NAME'),
'HOST': os.environ.get('DB_HOST'),
'PORT': '1433',
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'OPTIONS': {
'host_is_server': True,
'driver_supports_utf8': True,
'extra_params': 'tds_version=7.2;'
}
}
}
Per my experience, it seems to be caused by the tds_version that the 7.2 version does not support Azure SQL Database. Please refer to my answer for the other SO thread pymssql: Connection to the database only works sometimes to change to 7.3.
Possibly, the third-party project michiya/django-pyodbc-azure on GitHub may help for you to get the more details.
Hope it helps.
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.
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