DEV Community

Cover image for How to connect railway. app with nextjs using Prisma.
Next Dev
Next Dev

Posted on

How to connect railway. app with nextjs using Prisma.

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
Enter fullscreen mode Exit fullscreen mode

Then write

prisma init
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then check out the ‘schema.prisma’ file

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

prisma db push
Enter fullscreen mode Exit fullscreen mode

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

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

Code:



Now, you have to write the command

prisma migrate dev
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)