Django MongoDB Engine connection failure - django

[SOLVED] After successfully completing the django tutorial, I have tried to use mongoDB as a database, with Django MongoDB Engine. This is the database configuration in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'test',
'HOST': 'localhost',
'PORT': 27017,
# 'OPTIONS' : {
# 'slave_okay' : True,
# }
}
}
And this is the error message I get, after running python manage.py syncdb
:
raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary
I got this error, even after shutting down the mongoDB server, so I figured out that this needed to be a connection issue. I posted an answer on how I solved this.
Using Ubuntu 12.04 LTS x64, Python 2.7, django 1.4.2, mongoDB x86_64 2.2.1 (clean new install)

The way I solved this is so simple that I am almost ashamed at myself for asking the question in the first place, but I hope it will be useful:
I simply upgraded the Django MongoDB Engine by typing into the terminal:
sudo pip install git+https://github.com/django-nonrel/mongodb-engine --upgrade
And that's it.

Can you try running ...
db.repairDatabase()
... from the mongo terminal?

Related

Test database for Django + Heroku. Error creating the test database: permission denied to create database

I'm trying to run the tests for my Django project. I wrote this project some time ago, I had different settings then and tests were passing. Now I changed settings and deployed it on Heroku with Heroku Postgres database. Everything works fine already except I can't run tests. I've tried many different settings and nothing worked. Most of the time I'm getting this error: permission denied to create database
My last setting is following the instruction from this article on medium
Basically I have added 2nd Heroku Postgres database, add settings like below (but with valid variables of my heroku databases):
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'd7osdssadag0ugv5',
'USER': 'lhwwasadqlgjra',
'PASSWORD': '1524f48a2ce41177c4ssdadasd3a11680b735302d14979d312ff36',
'HOST': 'ec2-54-75-2326-118.eu-west-1.compute.amazonaws.com',
'PORT': 5432,
'TEST': {
'NAME': 'd7osdssadag0ugv5',
}
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'd7hasadas9hqts5',
'USER': 'nybkduadsdgqot',
'PASSWORD': 'bb535b9cdsfsdfdsfdsfac54851f267444dd8cc230b2a786ab9f446',
'HOST': 'ec2-54-247-132-38.eu-west-1.compute.amazonaws.com',
'PORT': 5432,
'TEST': {
'NAME': 'd7hasadas9hqts5',
}
}
}
Then run python manage.py test --keepdb in my venv. Then I get an error:
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
RuntimeWarning
Got an error creating the test database: permission denied to create database
I have also tried what is advised in this article
Do you have any ideas what I could do about this error? I don't know Django well. I play with it from time to time.
I'm using: Python 3.6.9, Django 3.0.3, Heroku Postgresql Hobby Dev
EDIT:
I'm not sure if this is now an issue with my settings DATABASES.
Now when I commented out all my settings concerning DATABASES and I run python manage.py runserver my development server starts as normal and I have access to a database I set before (even after restarting a computer). This looks like actual settings don't have effect (??) Any thoughts?
Django version 3.0.3, using settings 'forumproject.settings'
Starting development server at http://127.0.0.1:8000/
Ok, I found out what it was. My database settings were not taken into account, even I had DEBUG=True because I had this line on the end of the settings:
# Activate Django-Heroku.
django_heroku.settings(locals())
After commenting this out the error permission denied to create database
goes away and I can run tests with
python manage.py test --keepdb
I'm surprised how always posting a question on stack overflow help me to find answer immediately after. I was running in circles

connect mongodb with djongo (Django)

i try connect to mongodb with djongo
after reading githup page of djongo and this
find same question here but no answer as well
change setting.py like this
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'namename',
}
}
after run python manage.py makemigrate i get this error:
djongo' isn't an available database backend try using "django.db.backend.XXX" where XXX is one of : "mysql" , "oracle" , "postgresql" , "sqlite3"
mongodb version = 3.4
python version = 3.6.3
djogo == 1.2.38
You should downgrade Django version to 2.2.8 and reinstall the project.
You can use mongoengine to connect django with mongodb and add above line in your settings.py file.
import mongoengine
import pymongo
HOST = 'localhost:27017'
mongoengine.connect(
db='dbname',
host=HOST,
read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED
)
2022: It seems djongo doesn't work with the latest versions (4.X) of django and pymongo, because I solved the issue with:
django==3.2.14
pymongo[srv]==3.12.3
python version also matters: for me python 3.8.14 works. Tested with the following dependencies.
Python==3.8.14
Django==3.2.15
djongo==1.3.6
Mongo==3.6
pymongo==3.12.3
I think latest version of djongo with Django 3.x.x works perfect but pymongo, Mongo, and Python must be kept same.
First install djongo
pip install djongo
then next makemigration and migrate
i install djongo it works for me with latest version of django
my django version is 3.2.7
mython version is 3.8
pip install djongo will install the latest version,
in my case the command installed of djongo 1.3.6 by default
and change the DB in settings.py
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'db_name',
}
}

convert_datetimefield_value() takes 4 positional arguments but 5 were given using django with mongodb

Django Admin login page, I am using mongodb for django, after that only I got error
mongodb configure:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'django-mongo-db',
}
}
Click Here
You are using djongo as your backend engine, the requirement of djongo is Django==2.1.2. Please install the same as -
pip install django==2.1.2
I have faced this error in the past. Doing this resolved it.

How do I get Jython-Django to work with Postgresql JDBC

I have tried to setup an instance of Django on Jython using Postgresql. I can't get Django to talk to Postgresql. Can someone help me figure out what is wrong?**
So far, I have the following system installed for development:
Windows 7
JDK7 (x86)
Jython Version 2.7b2
Django-1.6.5
django-jython 1.7.0b2(Database backends and management commands, for development underDjango/Jython)
postgresql-9.3.5-1-windows-x64.exe
Eclipse-PyDev
I was able to run the server and database, but now I am having issues with configuring Django to work with the Postgresql database.
I followed the configuration steps here:
https://pythonhosted.org/django-jython/database-backends.html#postgresql
My settings.py file has the following:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'gate',
'USER': 'gate',
'PASSWORD': 'test',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
When I check my class path:
C:\>echo %CLASSPATH%
C:\Program Files (x86)\Java\jdk1.7.0_67\bin.;C:\Program Files (x86)\Java\jre7\li
b\ext\QTJava.zip
I have the JDBC file postgresql-9.3-1102.jdbc41.jar in the lib folder listed above.
Error Message from Django
File "C:\jython2.7b2\Lib\site-packages\django\db\utils.py", line 131, in load_backend raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'doj.db.backends.postgresql' isn't an available
database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named schema
I believe the problem is that you are using the wrong version of Django.
Jython-Django is compatible only starting from 1.7.
See https://docs.djangoproject.com/en/1.6/howto/jython/

Error was: No module named backends.spatialite.base

For testing purposes I'm trying to use SQLite, but it seems I'm missing the spatialite backend:
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.backends.spatialite' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named backends.spatialite.base
Any idea how I can make Django find it?
I have installed spatialite.
This is my db setup:
DATABASES['default'] = {
'ENGINE': 'django.contrib.gis.backends.spatialite',
'NAME': '/tmp/test.db'
}
Ubuntu 12.04.1 LTS; Python 2.7.3; Django 1.4.1
You should look for:
django.contrib.gis.db.backends.spatialite
not
django.contrib.gis.backends.spatialite
:)
trying importing from shell