Home > Mobile >  database does not exist postgresql
database does not exist postgresql

Time:04-12

I am working on connecting a Postgres DB to Django. I have created the db through pgAdmin 4 under the user postgres. I've set my environment variables as followed

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
try:
    if sys.argv[1:2] != ['test']:
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.postgresql',
                'HOST': env('PGHOST'),
                'USER': env('PGUSER'),
                'NAME': env('PGDATABASE'),
                'PASSWORD': env('PGPASSFILE'),
                'PORT': env('PGPORT'),
            }
        }
except:
    pass

with my .env file containing each variable. When I try to migrate it through ubuntu command line I get the error database <dbname> does not exist I've installed psycopg2 and pillow and set local all postgres peer to local all postgres md5. my os is windows 11 so I am wondering if this is happening because my project directory is through ~/directory/to/path and postgres and pgAdmin are installed in /etc/postgresql/ and /mnt/c/'Program Files'/PostgreSQL? Should I move those files from / to ~?

NOTE: I've run psql canvasDB and got back role "awilbur" does not exist

CodePudding user response:

If you installed postgresql through an installer (which I assume is the way since you're on Windows), you might've remembered that the installer asked you for a password. If you do remember, you should try:

me@My-MacBook-Pro ~ [2]> psql -U postgres
Password for user postgres: 
psql (14.2, server 14.1)
Type "help" for help.

postgres=# CREATE DATABASE test;
CREATE DATABASE

Specifying -U postgres will log you into the default user, whose default password is the password you entered into the installer.

If you don't, you could try this: go to the Control Panel -> Administrative Tools -> Computer Management. Under "Local Users and Groups" you can see all users created for your system. Remove "postgres" and reinstall PostgreSQL.

After you're done, you can verify by:

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
----------- ---------- ---------- --------- ------- -----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 template0 | postgres | UTF8     | C       | C     | =c/postgres           
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres           
           |          |          |         |       | postgres=CTc/postgres
 test      | postgres | UTF8     | C       | C     | 
(5 rows)
  • Related