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
Related
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?
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,',
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;
It might be simple thing but I just can't seem to get it running.
in my Django project's settings, I have these db settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PWD'),
'HOST': 'xxxx.yyyyy.eu-central-1.rds.amazonaws.com',
'PORT': '',
}
}
and in /etc/environment I have set the variables and also in .profile.
but this is just not working and I am getting:
(1045, "Access denied for user 'www-data'#'132.31.48.116' (using password: NO)")
If I remove and hardcode the credentials, it works. so obviously my env variables are located in wrong place. can someone please give some look at it?
I am using Debian 4.9.51-1 (2017-09-28) x86_64 in ec2 server
I want to test my django app in my WAMP server. The idea is that i want to create a web app for aaa.com and aaa.co.uk, if the user enter the domain aaa.co.uk, my django app will serve the UK version, if the user go to aaa.com, the same django app will serve the US version (different frontend). Basically i will be detecting the host of the user and serve the correct templates.
How do i setup my WAMP so i can test this? right now i am using pyCharm default server which is 127.0.0.1:8000
Ok the answer is basically ericeastwood.com/blog/3/django-setup-for-wamp combined with httpd.apache.org/docs/2.4/vhosts/name-based.html – shadow
first install mysqliclient module using below command
pip install mysqlclient
open settings.py file and change database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'yourdbname',
'USER': 'dbusername',
'PASSWORD': 'your password',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}