Skip to content

The Database

Jon Froehlich edited this page Nov 10, 2023 · 1 revision

Connecting to the Database

While not immediately necessary, as you start developing with Django, you'll likely want to peer directly into the database (for debugging, to confirm something, etc.). So, how do you connect to the database?

For the Makeability Lab website, we use a PostgreSQL backend for Django. You can see the specificications in the Docker YML file docker-compose-local.dev.yml (which you're hopefully using on your dev environment):

services:
  db:
     image: 'postgres:16' # We use the official Docker postgres image: https://hub.docker.com/_/postgres
     restart: always
     ports:
       - '6543:5432'
     environment:
      - POSTGRES_DB=makeability
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=password
     volumes:
      - postgres-data:/var/lib/postgresql/data

Note the line: ports: - '6543:5432', this exposes the Postgres connection outside of Docker to your OS. Then, you can use whatever tool you want to connect to the database, like psql (command line) or DBeaver (GUI). In this example, we'll use DBeaver using the settings specified above (in the YML) file.

image

Viewing a table

Once DBeaver has properly connected, you can view the tables, write queries, etc.

Here's our website_person schema: image

You can double click on the Data tab to view the contents: image

Clone this wiki locally