I install PostgreSQL version 10
also, install pgAdmin4
During the PostgreSQL installation, as Every developer know default username = Postgres
My PostgreSQL username was Postgres.
installation window asked me the password, so put the new password
Now when I connect PostgreSQL to my Django project
I install this module
pip install psycopg2
I created a new database using pgAdmin4 named 'mydb'
In my Settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USERNAME':'postgres',
'PASSWORD' : '<my_Password_here>' , # I entered the same password that i provided during postgres installation
'HOST' : 'localhost',
'PORT': '5432',
}
}
postgres username = 'postgres'
where
my Window Username = 'Huzaifa'
ERROR is here
django.db.utils.OperationalError: FATAL: password authentication failed for user "Huzaifa"
Why Postgres using my Window User (username) for authentication
NOTE:
I already set environment variables as following
C:\Program Files\PostgreSQL\10\lib
C:\Program Files\PostgreSQL\10\bin
After Posting this Question. I found what I was mistaking.
There is no Variable name USERNAME. change USERNAME to USER
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USERNAME':'postgres', # <-- Here is the Mistake -->
'PASSWORD' : '<my_Password_here>' ,
'HOST' : 'localhost',
'PORT': '5432',
}
}
Change to...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER':'postgres', # <-- Here is the Mistake -->
'PASSWORD' : '<my_Password_here>' ,
'HOST' : 'localhost',
'PORT': '5432',
}
}
Related
I just started learning django. I change the following settings from setting.py because I want to use mysql not sqlite:
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backend.mysql',
'NAME' : 'newprj',
'USER' : 'root',
'PASSWORD' : 'abcd',
'HOST' : 'localhost',
'PORT' : ''
}
}
then when I try this code python manage.py migrate on cmd. It throws an big error, I can't understand what is the problem, please help me solve it. This is the error:
You missed the s in django.db.backends.mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', #<---- You missed the s in backends
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
here's my code in django settings.py for the database:
DATABASES= {
'defualt': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cameronkc',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': ''
}
}
here's the error im recieving when executing >python manage.py migrate in command prompt
django.db.utils.ConnectionDoesNotExist: The connection default doesn't exist
You misspelled default in your DATABASES dict. Change 'defualt' to 'default'.
It's the first time I'm deploying a site using MySQL instead of SQLite3, so I'm quite new at this, after reading some documentation I found out that I have to change some files like this :
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_site_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': '?', #currently using pythonanywhere (not on localhost)
'PORT': '?',
}
}
manage.py
try:
import pymysql
pymysql.install_as_MySQLdb()
except:
pass
(PyMySQL==0.7.10, Django 1.9, Python 3.5)
When I run the Bash Console using python manage.py migrate I get this error message :
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
I thought it has something to do with the HOST and the PORT from the Database configurations, I don't know what I should add in these, does it have to do with MySQL, PythonAnywhere or even my own domain ? How can I resolve this problem and set up MySQL correctly with Django 3.5 ?
Check this guide. I used it to deploy my webapp.
You can use in this way
Username : johndoe
Database name : socialdatabase
Host : xyz.mysql.pythonanywhere-services.com
User : johndoe
Name : johndoe$socialdatabase
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_site_db', # Username$database name
'USER': 'username', #Username:
'PASSWORD': 'password',
'HOST': '?', # Database host address
}
}
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")
}
}
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'
}
}