Recently I started a Django project and for this project, I decided to use PostgreSQL inside of the default SQLite that comes with Django on a mac.
I ran into some issues that cost me a lot of billable hours, but I was finally able to fix it, hence this post so that nobody would waste lot of billable hours to setup PostgreSQL with Django.
There are some issues I encountered that may be peculiar to me, but also could be helpful to someone, so I would highlight that too.
Django supports PostgreSQL 9.0 and higher.
In case you do not have Postgres on your system already, I would recommend you downloading and installing it from the package app on their site.
If you are like me that I forgot the password I used for Postgres on my machine, there are several ways to change your password, but I had nothing to lose so I just uninstalled the app. Double-click the
uninstall-postgresql.app app in this directory
That would do a total clean-up for you, then you can install Postgres from the app you downloaded.
Install this inside virtual environment to connect Django with Postgresql database server
pip install psycopg2
psycopy2 is working by running this command
python -c "import psycopg2"
If you get any error with that command, check out my post on psycopg2 error and how I solved it.
You should install Django by running this command
pip install django
Create a database
Before Django can use Postgres it would need a database, you can create it from the GUI or run this command
CREATE DATABASE OWNER CREATE DATABASE
Set Postgres as your default database
The next thing to do is to update
Run your migration
Run your migration to create tables in the database
python manage.py migrate
If your see something like this
Then you have successfully setup Postgres with your Django app, if you encounter any challenges, please drop comments and let’s fix it then we update this post, to avoid others going through that also.