How to setup Prisma with your local PostgreSQL

Lada496
Jul 11, 2023

--

This is my memo when I tried t3 app with PostgreSQL for the first time.

Pre-requirements: install postgresql
OS: macOS

  1. psql postgres to enter postgres
  2. Create an user with CREATEDBpermission: CREATE ROLE <username> WITH LOGIN PASSWORD '<password>' CREATEDB;
  3. go to your app’s root folder
  4. make sure the provide is ‘postgresql’ at prisma/prisma.schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

5. Database url has the following structure: postgresql://username:password@localhost:5432/database-name
⚠️ If you don’t use the default port number, replace from 5432 to yours.

6. npx prisma migrate dev --name initial

Special thanks: https://www.codementor.io/@engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb

--

--