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?

v18o
  • 1,237
  • 2
  • 15
  • 25
  • Which django version are you using and can write the value of DATABASES – Mohammad Mustaqeem Nov 23 '17 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', } }` – v18o Nov 23 '17 at 17:07

2 Answers2

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',
  }
}
Mohammad Mustaqeem
  • 1,034
  • 5
  • 9
  • No, default is occupied with another db. I have 2 db in one app. And the default db work just fine. – v18o Nov 23 '17 at 21:16
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'),
Neil Anderson
  • 1,265
  • 12
  • 19