postgresql auth django (password authentication failed for user "BlogAdmin2") - python

I followed the tutorial posted by Digital Ocean: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#create-and-configure-a-new-django-project (How to set up django with postgres nginx and gunicorn on ubuntu)
I created a git hub private repo with the website and when I created the postgresql database with the folowing commands:
CREATE DATABASE PiaBlog;
CREATE USER BlogAdmin WITH PASSWORD 'Andrei1234';
ALTER ROLE BlogAdmin SET client_encoding TO 'utf8';
ALTER ROLE BlogAdmin SET default_transaction_isolation TO 'read committed';
ALTER ROLE BlogAdmin SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE PiaBlog TO BlogAdmin;
\q
and here is my django database config:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'PiaBlog',
'USER': 'BlogAdmin',
'PASSWORD': 'Andrei1234,',
'HOST': 'localhost',
'PORT': '',
}
}
When I run python manage.py migrate I get :
django.db.utils.OperationalError: FATAL: password authentication failed for user "BlogAdmin2"
FATAL: password authentication failed for user "BlogAdmin2"
Does somebody know why do I get this problem I spent an hour searching for a typing error and I never found it.
Then I created a new user and I had this error:
django.db.utils.OperationalError: FATAL: password authentication failed for user "blog_admin"
FATAL: password authentication failed for user "blog_admin"
This is what I did:
CREATE DATABASE blogdb;
CREATE USER blog_admin WITH PASSWORD 'testing1234';
ALTER ROLE blog_admin SET client_encoding TO 'utf8';
ALTER ROLE blog_admin SET default_transaction_isolation TO 'read committed';
ALTER ROLE blog_admin SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE blogDB TO blog_admin;
\q
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'blogdb',
'USER': 'blog_admin',
'PASSWORD': 'testing123',
'HOST': 'localhost',
'PORT': '',
}
}

Is this comma supposed to be in your password?
'PASSWORD': 'Andrei1234,',

Related

error issue on connecting mysql for django project

I am new to Django.i am learning Django for the past few weeks,i have some trouble on changing the databse to sqllite to mysql.
setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': ' ',
'HOST': 'localhost',
'PORT': '3306',
}}
When i try to run the server using py manage.py runserver
It show me the error like
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
SPECIFICATION
python-3.8
django-3
MySQL(xampp)
OS-windows
This is most likely an issue with your USER, PASSWORD or HOST fields. You are probably not providing correct values. Try executing mysql -u root -p -h localhost and enter the password when asked for it. You should get the same error.
My guess is your password is just empty. So delete the space character for password and it should work.
If that is the case, you should really set a password. Refer to this - How to reset or change the MySQL root password?

Unable to connect to the localhost/phpmyadmin database through my django project

I am trying to connect to the localhost/phpmyadmin through xampp server for my django project. When i type
python manage.py runserver
on my command prompt, i'm getting error.
django.db.utils.OperationalError: (1044, "Access denied for user ''#'localhost' to database 'djangoproject'")
There is no password set on my phpmyadmin, it is just by default user 'root' and password [null]
I have written the below code in my manage.py file to connect to the database page.
DATABASES = {
'default' : {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangoproject',
'USER': ' root ',
'PASSWORD': '',
'HOST': 'localhost',
'PORT':''
}
}
There is also this in my phpmyadmin page on the top
A user account allowing any user from localhost to connect is present. This will prevent other users from connecting if the host part of their account allows a connection from any (%) host.
I do not understand what is wrong. I am a beginner in django framework.
Your user does not have an access to the database. Use the commands below to set up your database
DROP DATABASE IF EXISTS `mydb`;
CREATE DATABASE `mydb`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE 'mysql';
GRANT ALL PRIVILEGES ON mydb.* TO 'mydb_user'#'localhost' IDENTIFIED BY 'your_password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;

Django:permission denied for relation django_migrations, PostgreSql - django user?

I ve been struggling about figuring out relation between postgre users and linux users and the permissions between them.First question I want to ask is that ,let s assume I have tom linux user and tom postgre user which I created with psql command.What is the relation between those two? The reason I am asking is realated with following question:
I am using vagrant and ubuntu in it.There is 2 userss , first one is Linux "vagrant" user , second one is PostgreSql "vagrant" user which I created through following commands:
CREATE USER vagrant WITH PASSWORD '123.123';
GRANT ALL PRIVILEGES ON DATABASE cashier to vagrant;
which should means and also is that vagrant have all permissions on cashier database.
I should also mention as an aside note that I am using provisioning and vagrant uses root user when executing provisions , so root should also have all permissions on the cashier databse because I am importing dump into cashier database on provisioning.
so you can easily assume root have granted permissions through :
CREATE USER root WITH PASSWORD 'vagrant';
GRANT ALL PRIVILEGES ON DATABASE cashier to root;
Here is the problem: When I try to runserver in django python manage.py runserver
if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': '123.123',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
I get authentication error, and if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': 'vagrant',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Then i have Django:permission denied for relation django_migrations, problem.Simply my question is What is going on?What is the relation between users?Which user should i use ? Why django cant migrate with both user credentials?
Recall :
Linux user vagrant pass vagrant
Postgre user vagrant pass 123.123

django.db.utils.OperationalError: (1046, 'No database selected')

Getting a strange error. I created a database in MySQL, set the database to use it. Using the right settings in my Django settings.py. But still there's an error that no database has been selected.
First I tried:
python manage.py syncdb
Got this traceback:
django.db.utils.OperationalError: (1046, 'No database selected')
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
What have I missed?
Check to make sure your database my_db exists in your MySQL instance. Log into MySQL and run;
show databases;
make sure my_db exists. If it does not, run
create database my_db;
GRANT access privileges to the user mentioned in the file
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
You need not grant all privileges. modify accordingly.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
Here name means database
Just delete database my_db and create again
Step 1:- Use drop database databaseName
Step 2:- Create Database databaseName
Then use the migrate command
It will definitely work

How to configure settings.DATABASES?

./manage.py syncdb shows some error
(ENV)vijay#vijay-Ideapad-Z570:~/nightybuild/heroku-landing$ ./manage.py syncdb
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
(ENV)vijay#vijay-Ideapad-Z570:~/nightybuild/heroku-landing$
in my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
but my app running successfully in heroku. when deploy its automatically heroku postgres confiqured. But in the local development its showing this error .
Can you please tell guide me how to set database for local?
What type of database are you using? Postgres, MySQL, SQLite? That will be your ENGINE value.
Also, what is your local postgres username and password? And your database name?
Below is an example with a postgres database named testdb with the username myusername and password mypassword:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testdb',
'USER': 'myusername',
'PASSWORD': 'mypassword',
'HOST': '',
'PORT': '',
}
You may need to alter depending on your needs. The biggest change will likely be your ENGINE value. Change postgresql_psycopg2 to mysql if using MySQL or sqlite if using SQLite. Also, if using SQLite, you won't have values for USER and PASSWORD.

Categories