Setting up PostgreSQL for use with a Django database — without errors

As a technical writer, there’s something that frustrates me very much — instructions that just don’t work. It really grinds my gears. When I write instructions on how to accomplish a task, something I always make sure to do is actually test the instructions to make sure that they work and lead to the expected result, because when I am following specific instructions and things don’t work it really frustrates me as someone who has ADHD.

So I’m setting up a Django project, and naturally I wanted to use PostgreSQL with the project.  I just don’t like SQLite, it’s something I’m forced to use with Calibre and it causes problems with database portability — I have to have the application on the same host as the database and that’s a pain in the ass.

So I modify the venv in which Django is running and install psycopg2-binary, which has the PostgreSQL bindings for Django, and modify the settings.py file to point to the correct database.

Then I went online and the instructions everywhere are always this:

Log into PostgreSQL as the root user (e.g. psql -U postgres)
In psql:
CREATE DATABASE new_database;
CREATE USER new_user WITH PASSWORD 'newpassword';
GRANT ALL PRIVILEGES ON DATABASE new_database TO new_user;

This does not work! Well, it doesn’t work with PostgreSQL 16 and Django 6. When you go back to your django project, make the migrations, and migrate the project, you end up with this error:

psycopg2.errors.InsufficientPrivilege: permission denied for schema public

The worst part of this is, it’s not a new problem. After searching online, this is something that’s been pointed out for several years, and yet none of the “AI-powered search results” seem to be aware of this. It’s really not changing my opinion that search engine-generated “AI summaries” are crap that no one has ever verified — like most AI generated slop out there.

The missing instruction is that you have to, as the postgres user, log into the new database and ALSO grant the privileges to the public schema of the new database to the new user.

To do this, you must do this in a separate operation from the one that created the database:

Log into the new PostgreSQL database as the root user (e.g. psql -U postgres -d new_database)
In psql,
GRANT ALL PRIVILEGES on SCHEMA public TO new_user;

Once you do this, you can perform the database migrations as expected.

It’s really annoying that I even have to write this.  Most search engines now will provide you with instructions that don’t work, and this is directly  due to their decision to pollute their search results with unverified AI slop that just doesn’t work. It’s very frustrating and will probably continue being an issue as long as tech companies continue to insist on burdening the rest of us with this “artificial intelligence” monster they’ve sunk billions/trillions of dollars into, while laying off hundreds of thousands of employees and essentially killing the software job market.