How to connect railway. app with nextjs using Prisma.

How to connect railway. app with nextjs using Prisma.

·

2 min read

Welcome 👋 friends to this new blog post where I will teach you how to connect railway and nextjs with the help of Prisma.

Requirements:

  1. Nextjs Project (Frontend Framework)

  2. Railway.app (This is for the database)

  3. Prisma (I will tell you how to install it.) (ORM tool)

Step1: Make a railway.app project

Then make a postgress database.

Step2: Open your nextjs project.

Then open a terminal and write this command.

yarn add @prisma/client

Then write

prisma init

Then you will find a new folder called Prisma in your root folder.

Then go to .env

Before changing anything in .env , go to

Then change this in your .env file.

Now you can see this tutorial:

🤔Situation

Now you have two situations. Either you have tables or you don’t have any tables inside your database.

1. If you have tables in your database.

Just write the command

prisma db pull

Then check out the ‘schema.prisma’ file

2. You have tables. But you want to update them by prisma file.

prisma db push

3. You don’t have any tables in your database.

For example, write this command in your ‘schema.prisma’ to make tables.

Code:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}


model users{
  id Int @id @default(autoincrement())
  name String
  email String
  password String
}

Now, you have to write the command

prisma migrate dev

Then it will ask you for your migration name. You can write there anything you want.

Then you will see one folder as Migrations in your Prisma directory.

You can check your database and see the results.

Thanks for reading this blog.

If any question arises in your mind, feel free to ask here 👇 Join the Next Dev Discord Server!

If you want to see a video tutorial in Hindi: https://youtu.be/Su047Z6FBN4

Did you find this article valuable?

Support Next Dev by becoming a sponsor. Any amount is appreciated!

Â