Try using 'django.db.backends.XXX', where XXX is one of: - python

I was setting Django up to use PostgresQL and for some reason, it won't connect it keep giving me this error:
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
here's the code for it in setting.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DBNAME',
'USER': 'postgres',
'PASSWORD': 'DBPW',
'HOST': 'localhost'
}
}
I had the exact same code in a different project and it works perfectly fine!

you need to pip install psycopg2, looks like the Postgres adaptor is not installed

use this config instead of your config:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DBNAME',
'USER': 'postgres',
'PASSWORD': 'DBPW',
'HOST': 'localhost',
'PORT': '',
}
}
your ENGINE is not correct.

Related

django.db.utils.OperationalError: FATAL: database "clinilead_e " does not exist

After changing the db from sqlite to postgresql(python manage.py makemigrations)running, I am getting this error.How could i overcome this?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'clinilead_e ',
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
In postgres, unlike sqlite you have to create the database.
$ createdb clinilead_e

Multiple Databases --Migrations

I am using 2 postgres databases in my django app.
'newpostgre': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'new_postgre2',
'USER': 'tester',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
},
'newpostgre2': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'new_postgre3',
'USER': 'tester',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
},
I have a very simple model
class Check1(models.Model):
title = models.CharField(max_length=100)
I had run
python manage.py migrate --database=newpostgre
python manage.py migrate --database=newpostgre2
when I open my new_postgre2(for newpostgre) database in postgre, I can see my Check1 table there.
But in my new_postgre3(for newpostgre2) database in postgre, no Check1 table is there, only those initial migrations are there.
Why I can't see my table in new_postgre3 when migrations have been successfully made?
Because The same object name can be used in different schemas sometimes conflict. The best practice allow many users to use one database without interfering with each other. Use this change second database user and check again. I think it is work.
'newpostgre': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'new_postgre2',
'USER': 'tester',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
},
'newpostgre2': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'new_postgre3',
'USER': 'tester_different',
'PASSWORD': 'password_different',
'HOST': 'localhost',
'PORT': '',
},
python manage.py migrate --database=newpostgre2

How to configure Django database using Heroku?

I'm using Heroku with Django.
The database is configured in settings.py this way, using the dj-database-url module:
DATABASES = {'default': dj_database_url.config()}
How can I do to add additional parameters, for example ATOMIC_REQUESTS? In a "normal" case I would do like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
'ATOMIC_REQUESTS': True,
}
}
DATABASES is just a dictionary: you can add the relevant settings after the initial configuration.
DATABASES = {'default': dj_database_url.config()}
DATABASES['default']['ATOMIC_REQUESTS'] = True

Django sql connection failed

I have created new project in django and write mysql connection in it's settings file like :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'optdb',
'User': 'root',
'Password':'975',
'Host':'127.0.0.1',
'Port':'8080',
}
}
Now i write command : python manage.py syncdb and that generates following error:
How to solve this error mentioned above?
Note: I have currently one user in my MYSQL WAMP SERVER that is root with host 127.0.0.1.
All of those keys should be in capitals.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'optdb',
'USER': 'root',
'PASSWORD':'975',
'HOST':'127.0.0.1',
'PORT':'8080',
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'optdb',
'USER': 'root',
'PASSWORD':'975',
'HOST':'127.0.0.1',
'PORT':'8080',
}
}
It's case sensitive...
Also, are you sure your mysql server is at port 8080? That's unusual. If unsure, just leave out that line and default mysql port will be used. See How can I connect to MySQL on a WAMP server?

How to use a specific database for a single test in django?

Does anyone kno how to use a specific database for a single test in Django?
EDIT: At the moment, i'm using sqlite for testing, but, i want to use a mysql database for a specific test (def test_benchmark...), which will benchmark some sql statements.
Thanks
I don't know of any builtin way to do it - but I didn't look for it neither honestly. One possible (dirty) hack is to check what's in sys.argv in your settings (which is just another Python module) and have an alternate database settings for your particular test, ie:
# settings.py
import os, sys
DATABASES = {
'default': {
'NAME': 'db_name',
'ENGINE': 'your.engine',
'HOST': 'server',
'USER': 'django',
'PASSWORD': 'django',
}
}
if "test" in sys.argv and "your-test-name" in sys.argv:
DATABASES = {
'default': {
'NAME': 'other_db_name',
'ENGINE': 'your.engine',
'HOST': 'server',
'USER': 'django',
'PASSWORD': 'django',
}
}
In Django you set the database in your settings.py file. The configuration should look something like this:
DATABASES = {
'default': {
'NAME': 'db_name',
'ENGINE': 'sql_server.pyodbc',
'HOST': 'server',
'USER': 'django',
'PASSWORD': 'django',
'OPTIONS' : { "use_mars" : False,
"provider" : "SQLNCLI10",
"extra_params" : "MARS Connection=True"},
}
}

Categories

Resources