unable to connect to postgresql server

Okay, I’m creating a completely new db. I’m in the postgres=# shell now. So I create a new db with this command CREATE DATABASE right?

Don’t summarize or “describe” anything. If you want confirmation of commands, please post the complete command you are trying to use.

postgres=# CREATE DATABASE myproject;. myproject is a demo database as per the tutorial I shared a link to

1 Like

(Note: If what you post is correct, I’ll indicated that by using the “heart” icon rather than create a full post simply to say “that’s correct”.)

postgres=# CREATE DATABASE arbordb;

1 Like

CREATE USER cortek WITH PASSWORD 'arbortek78';

1 Like

This is fine too, but I’m not sure why you created “myproject” if the database you’re going to be using is “arbordb”.

I see what you mean, as I already pointed out earlier. myproject is the username the tutorial is using. I’m not using this db name, I’m using arbordb

postgres=# GRANT ALL PRIVILEGES ON DATABASE arbordb TO cortek;

1 Like

Okay now what should I do. Should I start the postgresql server and run python manage.py makemigrations?

Isn’t PostgreSQL still running?

Anyway, let’s check basic configuration first. Run the following psql command from the command line:
psql -h localhost -U cortek arbordb, and when it asks for the password, enter arbortek78

I assume it is running, I just thought to be safe. I’ll run it right now

It didn’t ask for the password after I entered this command. I’m in the postgres=# shell by the way

Something’s not right - can you exit the shell, try it again, and copy/paste the command entered and the output from that command? (Please post the complete block of text, including all the header information after the command and before the prompt.)

For example, this is what I see on one of my test systems:

 tskww@ubuntu:~/Desktop$ psql -h localhost -U tskww tskww                                             
 Password for user tskww:                                                                             
 psql (17.2 (Ubuntu 17.2-1.pgdg22.04+1), server 15.10 (Ubuntu 15.10-1.pgdg22.04+1))                   
 SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)     
 Type "help" for help.                                                                                
                                                                                                      
 tskww=#                                                                                              

Okay, I’ll try it outside the shell now

(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ psql -h localhost -U cortek arbordb
Password for user cortek: 
psql (16.8 (Ubuntu 16.8-0ubuntu0.24.10.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

arbordb=> 

Excellent! Now, set your Django settings to this account information and give it a try.

1 Like

Can I exit out of the shell and run the migrations now?

1 Like

I got this after running python manage.py migrate

show_sunset_warning()
Operations to perform:
  Apply all migrations: admin, arborchat, arborfindr, auth, contenttypes, django_rest_passwordreset, sessions
Running migrations:
Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.InsufficientPrivilege: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 78, in ensure_schema
    editor.create_model(self.Migration)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 505, in create_model
    self.execute(sql, params or None)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 45, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 202, in execute
    cursor.execute(sql, params)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.ProgrammingError: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/manage.py", line 23, in <module>
    main()
  File "/home/corey-james/Arborhub/MyProject/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 357, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 107, in migrate
    self.recorder.ensure_schema()
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 80, in ensure_schema
    raise MigrationSchemaMissing(
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^
)
(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ 

While in the psql shell in the arbordb database, run:

grant all on schema public to cortek;

1 Like