1

I have Django app with PostgreSQL.

The app has those environment variables:

DATABASE_HOST=localhost
DATABASE_USER=admin
DATABASE_PASSWORD=admin

Here is psql output:

postgres=# CREATE USER admin WITH PASSWORD 'admin123';
ERROR:  role "admin" already exists


postgres=# select * from USER;
 current_user
--------------
 postgres
(1 row)

postgres=# GRANT ALL privileges ON DATABASE my_db to admin;                 
GRANT

When I try to take something from db I get ProgrammingError: permission denied for relation app_rangeslot.

So, the questions:

1) If user admin have all rights, why I get permission denied error?

2) If user admin is created, why I cannot see it?

2
  • Which django version are you using and can write the value of DATABASES Commented Nov 23, 2017 at 17:00
  • @MohammadMustaqeem Django version is 1.8 DATABASES = { 'my_db': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': os.getenv('DATABASE_NAME', 'my_dev'), 'USER': os.getenv('DATABASE_USER', 'postgres'), 'PASSWORD': os.getenv('DATABASE_PASSWORD', os.getenv('DATABASE_PASSWORD', '')), 'HOST': os.getenv('DATABASE_HOST', os.getenv('DATABASE_HOST', '')), 'PORT': '5432', } } Commented Nov 23, 2017 at 17:07

2 Answers 2

1

I think you are missing 'default' key in the DATABASES dict. Your settings should be as given below:

DATABASES = {
  'default': {
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'NAME': os.getenv('DATABASE_NAME', 'my_dev'),
      'USER': os.getenv('DATABASE_USER', 'postgres'),
      'PASSWORD': os.getenv('DATABASE_PASSWORD', ''),
      'HOST': os.getenv('DATABASE_HOST', ''),
      'PORT': '5432',
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

No, default is occupied with another db. I have 2 db in one app. And the default db work just fine.
0

I think you are connected as the postgres user

      'USER': os.getenv('DATABASE_USER', 'postgres'),

don't you want to actually connect as the admin?

      'USER': os.getenv('DATABASE_USER', 'admin'),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.