postgresql django not sending password - python

I am getting the error OperationalError: fe_sendauth: no password supplied on my production server but I cannot see why...
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': PROD_DB_PASSWORD,
'HOST': 'localhost',
'PORT': '5432',
}
}
pg_hba.conf:
host dbname dbuser localhost md5
If I do psql -d dbname -U dbuser -h localhost and then enter the password at the prompt I can see that it works so IDK why django is not sending the password and IDK where to look from here.

I suspect you're not passing the password correctly. Here's how you debug. After the DATABASES line in settings.py, can you try printing out the dict.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': PROD_DB_PASSWORD,
'HOST': 'localhost',
'PORT': '5432',
}
}
print DATABASES
Then manage.py runserver as you would.
See if the password is properly passed. Apologies my rep's not enough to comment yet.

For future readers also check the spelling and later cases. All database keys must be in UPPER CASE e.g ENGINE, NAME, USER, PASSWORD, HOST and PORT.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv("DB_NAME", "db_name"),
"USER": os.getenv("DB_USERNAME", "db_user"),
"PASSWORD": os.getenv("DB_PASSWORD", "db#password"),
"HOST": os.getenv("DB_HOST", "localhost"),
"PORT": os.getenv("DB_PORT", "5432")
}
}

Related

OperationalError in django when adding a new record

I have created a mysql database with Cpanel . And I have some settings for database in the settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '*****_db',
'USER': '******',
'PASSWORD': '********',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': { 'init_command': 'SET storage_engine=INNODB,character_set_connection=utf8,collation_connection=utf8_unicode_ci'
}
}
}
but the problem is when I try to add a new record in django-admin with some arabic chars , I get this error :
OperationalError at /admin/courses/arguments/add/
(1366, "Incorrect string value: '\\xD8\\xB3\\xDA\\xAF' for column `asiatrad_db`.`courses_arguments`.`name` at row 1")
What is the problem ? Do I need to create a new database with charset on utf-8 ?
The “utf8” encoding only supports three bytes per character. The real UTF-8 encoding, which everybody uses, needs up to four bytes per character. See this article.
So use “utf8mb4” charset instead of “utf8”.
The settings.py should look as follows:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '*****_db',
'USER': '******',
'PASSWORD': '********',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': { 'init_command': 'SET storage_engine=INNODB','charset': 'utf8mb4'}
}

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

MySql configuration for Django

I am getting error when try to run
python manage.py migrate
django.db.utils.OperationalError: (1045, "Access denied for user 'someuser'#'localhost' (using password: NO)")
This is my database setting inside setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/config/mysql.cnf',
},
}
}
config/mysql.cnf
[client] database = dbname user =
root password = passwt host = localhost
default-character-set = utf8
The MySql configs can be provided in settings.py file, as like below
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4',
}
} }
If need to configure with external file, below may be helpful
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': os.path.join(BASE_DIR, 'mysql.cnf'),
}
} }
The mysql.cnf file should be in project dir

Why I cannot create a database for graphite-web?

I am trying to install graphite-web on my computer by following the instructions on
https://gist.github.com/surjikal/2777886. When I try to populate the database with manage.py syncdb it does not find a proper database throwing the following error:
> sudo python manage.py syncdb
OperationalError: FATAL: database "/opt/graphite/storage/graphite.db" does not exist
Here you can find my database configuration from local_settings.py:
DATABASES = {
'default': {
'NAME': '/opt/graphite/storage/graphite.db',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'graphite',
'PASSWORD': '<password>',
'HOST': 'localhost',
'PORT': '5678'
}
}
Postgres is running properly:
sudo service --status-all | grep postgres
...
[ + ] postgresql
Why manage.py syncdb cannot create / find the graphite.db file?
If you are using postgresql then database path will not be required. You just need database name. like
DATABASES = {
'default': {
'NAME': 'graphite',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'graphite',
'PASSWORD': '<password>',
'HOST': 'localhost',
'PORT': '5678'
}
}

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?

Categories

Resources