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',
}
}
Related
I am confused since the documentation for oracledb clearly states that everything past 12.1 should work fine. Could someone please explain to me where I went wrong? The error was created when I tried to create migrations.
The document I am referencing is: oracledb docs
Here is the error:
django.db.utils.NotSupportedError: Oracle 19 or later is required (found 12.2.0.1.0).
And here is my databases string in my settings.py:
from pathlib import Path
import sys
import oracledb
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb
#the above line was added because of error (django.core.exceptions.ImproperlyConfigured: Error
#loading cx_Oracle module: No module named 'cx_Oracle')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': (
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server123)(PORT=1521))'
'(CONNECT_DATA=(SERVICE_NAME=server.domain.com)))'
),
'USER': 'user123',
'PASSWORD': 'password',
'OPTIONS': {
'threaded': True,
},
}
}
It's a Django thing. From docs.djangoproject.com/en/4.1/ref/databases/#oracle-notes:
"Django supports Oracle Database Server versions 19c and higher."
Also see the Django 4.0 release notes
"Dropped support for Oracle 12.2 and 18c".
Try an older version of Django if you can't upgrade the DB
I'm new to Django and I'm trying to display the result that comes from a Snowflake database. I know that Django has multiple built-in database backend engines like: django.db.backends.postgresql and django.db.backends.mysql among the other few it supports.
Unfortunately, I couldn't find a proper way of configuring a database backend engine in the
settings.py
When I enter sqlalchemy or snowflake-sqlalchemy as the engine, I get this error:
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
My guess was to go with sqlalchemy as that's what I usually use to connect to Snowflake outside of Django but for some reason, it's not working properly.
I'd appreciate any guidance on that.
2022 update: There's now a Snowflake backend for Django funded by
Snowflake customers and implemented by Django's Tim Graham:
https://github.com/cedar-team/django-snowflake
From their docs:
Install and usage
Use the version of django-snowflake that corresponds to your version of Django. For example, to get the latest compatible release for Django 3.2.x:
pip install django-snowflake==3.2.*
The minor release number of Django doesn't correspond to the minor release number of django-snowflake. Use the latest minor release of each.
Configure the Django DATABASES setting similar to this:
DATABASES = {
'default': {
'ENGINE': 'django_snowflake',
'NAME': 'MY_DATABASE',
'SCHEMA': 'MY_SCHEME',
'WAREHOUSE': 'MY_WAREHOUSE',
'USER': 'my_user',
'PASSWORD': 'my_password',
'ACCOUNT': 'my_account',
},
}
Some of the discussion while implementing it:
https://groups.google.com/g/django-developers/c/po9dS-2h4lg/m/UeKBoL8dBgAJ?pli=1
You should install a custom Snowflake engine like the following ones. Note that, as of today, those are incomplete. Though, it should not be difficult to implement missing Django features by completing the operations.pyfile.
-> https://github.com/pricemoov/django-snowflake
or
-> https://pypi.org/project/django-snowflake-backend/
please install snowflake-connector-python .E.g. below
pip3 install snowflake-connector-python==1.8.1
Here is the code to connect from SQL Alchemy.
=====================================================================
#!/usr/bin/env python
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
engine = create_engine(URL(
account = 'XXXX',
user = 'XXXX',
password = 'XXXXX',
database = 'XXXXXX',
schema = 'XXXXXX',
warehouse = 'XXXXX',
role='XXXXXXXX',
))
try:
connection = engine.connect()
connection.execute(
"CREATE OR REPLACE TABLE test_async(c1 TIMESTAMP_NTZ,c2 VARIANT)",_no_results=True)
finally:
connection.close()
engine.dispose()
=========================================================================
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.
[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?
I'm having some issues setting up django-mssql on Win Server 2008 R2. I have everything installed, however, the wiki for django-mssql says to setup the settings file similar to:
DATABASES = {
'default': {
'NAME': 'my_database',
'ENGINE': 'sqlserver_ado',
'HOST': 'dbserver\\ss2008',
'USER': '',
'PASSWORD': '',
'OPTIONS' : {
'provider': 'SQLOLEDB',
'use_mars': True,
},
}
}
When I run from my site directory:
python manage.py syncdb
I get an error stating it isn't an available database backend. When I installed django-mssql it seemed to install the backend here \site-packages\django_mssql-1.0.1-py2.7.egg\sqlserver_ado does this need to be copied to site-packages\django\db\backends?
I get the same error if I set my settings to:
DATABASES = {
'default': {
'NAME': 'my_database',
'ENGINE': 'django_mssql-1.0.1-py2.7.egg.sqlserver_ado',
'HOST': 'dbserver\\ss2008',
'USER': '',
'PASSWORD': '',
'OPTIONS' : {
'provider': 'SQLOLEDB',
'use_mars': True,
},
}
}
Am I missing something when setting up this backend? This is my first time using django, but I didn't see anything in the documentation for setting up a different backend, and the django-mssql wiki or issues doesn't seem to have anything either.
Also, if there is other documentation somewhere that can help please let me know.
EDIT: The django app is running on Ubuntu server.
Dustin's comment about making sure "import sqlserver_ado" from the command shell got me going down the right path on my Django 1.8.1, Python 3.5 Win32 system with pywin32 installed.
SPOILER ALERT This only gets my Django instance to run without errors. I haven't tested the ADO connection yet.
The first error message I got was:
No module named 'django.db.backends.util'
and I found there is a file called: django.db.backends.utils so I copied it and renamed it to django.db.backends.util (without the 's') and away went the error message!
So hoping this wasn't too harmful, I continued on this line of troubleshooting.
The next error message I got was:
File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\base.py", line 7, in <module>
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient
ImportError: cannot import name 'BaseDatabaseWrapper'
I changed line 7 in base.py to now say:
#from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation, BaseDatabaseClient
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.base.features import BaseDatabaseFeatures
from django.db.backends.base.validation import BaseDatabaseValidation
from django.db.backends.base.client import BaseDatabaseClient
Yes, that's commenting out the bad line and adding four separate lines.
Then I got this error:
File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\base.py", line 18, in <module>
from .introspection import DatabaseIntrospection
File "C:\Program Files (x86)\Python35-32\lib\site-packages\sqlserver_ado\introspection.py", line 3, in
from django.db.backends import BaseDatabaseIntrospection
ImportError: cannot import name 'BaseDatabaseIntrospection'
so I changed the line 3 to now read:
from django.db.backends.base.introspection import BaseDatabaseIntrospection
and so on for creation.py:
from django.db.backends.base.creation import BaseDatabaseCreation
for operations.py:
from django.db.backends.base.operations import BaseDatabaseOperations
for schema.py:
from django.utils.log import getLogger
Hope this helps someone. Hope the ADO module actually connects to something.
-Sean
You will want to make sure that you can import "sqlserver_ado" from your python shell.
Put the folder sqlserver_ado somewhere on your PATH, I put mine in \site-packages\
Take a look at the README.txt.
The engine does want to be set to "sqlserver_ado" similar to how the settings are done on the settings sample page.
As of 2019:
I couldn't get Django MSSQL to work at all.
I switched over to django-pyodbc-azure and that works great.
Install:
pip install django-pyodbc-azure
Setup:
'ENGINE': 'sql_server.pyodbc'
You need to install the dependency PyWin32. You can install via pip or download from the python binaries page http://www.lfd.uci.edu/~gohlke/pythonlibs/
I was trying to get django_pyodbc to work, and couldn't. I was getting this error:
django.core.exceptions.ImproperlyConfigured: 'django_pyodbc' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: cannot import name BaseDatabaseWrapper
I was directed to this post as a solution, so I'll post my answer here also.
I downgraded to django 1.6 instead of 1.8, and now django_pyodbc works as a database backend.
As per https://github.com/lionheart/django-pyodbc/pull/96, django_pyodbc should now work with Django 1.8. So this seems to be a good alternative to django-mssql for those requiring SQL Server 2008 R2 support.