Two things to note: One, I am executing these commands with my virtual environment running. So terminal appears as (env):
. Two, every time I tried to enter su postgres
, it asked me for a password.
I am reading a book on Django(using a mac), the text says:
"If you are using macOS, download PostgreSQL from https://www.postgresql.org/download/ and install it. You also need to install the Psycopg2 PostgreSQL adapter for Python. Run the following command to install it: pip install psycopg2==2.7.4
."
I already had postgres installed on my machine, as I was previously fumbling with trying to deploy a website, before reverting back to this example project I had built. So I did not go to the website and install it. I installed psycopg2 as instructed ((env): pip install psycopg2==2.7.4.
)
"Let's create a user for our PostgreSQL database. Open the shell and run the following commands: su postgres
then createuser -dP blog
"
I was thinking that "open the shell" meant enter the python virtual shell? So:
python manage.py shell
then
su postgres
this did not work, it asked me for a password. Exited the shell, ran the same command (env): su postgres
, same result.
From there I thought maybe since I am in a virtual environment I do have to redownload postgres
. I ran pip install postgres
(did not know if this would download something, but it did, so I didn't bother going to the website/also would not know how to install it to this environment from the website). Note, this installed postgres
as well as psycopg-someversion-binary
. So now I have psycopg2==2.7.4
and some version of psycopg2-binary
installed. From there I ran (env): su postgres
(note from my environment). The same result, it asked for a password.
Then I reentered my python interactive shell with python manage.py shell
and again ran su postgres
. Same result.
At this point, I tried to research it on my own. What I read said I need to run su - postgres
from root(?) by entering sudo -i
at the terminal. I did this, now I am at Justins-MBP:~ root#
(this does not seem it is at all related to the django project I am trying to use a postgres db for). Anyway, from here su - postgres
and as you might have guessed, it asked me for a password.
Any help on how I can properly switch the db is greatly appreciated.
Also, after typing all of this and thinking about what I did I realized I haven't changed the database settings of the python project yet. But neither has the book, so not really sure how this project would even be aware of this database?