W
Wasp-lang•3mo ago
mb23

Deploying Migration fails

During the server build process, I keep getting this error message:
[email protected] db-migrate-prod prisma migrate deploy --schema=../db/schema.prisma
Prisma schema loaded from ../db/schema.prisma Datasource "db": PostgreSQL database "railway", schema "public" at "monorail.proxy.rlwy.net:44462" 38 migrations found in prisma/migrations Error: P3009 migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve The 20240827213607_27082024 migration started at 2024-08-28 04:47:15.491352 UTC failed Somehow, yesterday's migration failed and now, I don't really know how to remove this migration. I've already created a new migration and on my local machine, everything works fine. Only if I want to deploy to Railway, I got this error message.
7 Replies
kapa.ai
kapa.ai•3mo ago
Hi @mb23. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided, it seems like you're encountering a migration issue with Prisma in your Wasp project. The error message suggests that a previous migration has failed and is preventing new migrations from being applied. To resolve this issue, you should follow the instructions provided in the error message, which direct you to Prisma's documentation on resolving migration issues in a production database. You can find the documentation here (https://pris.ly/d/migrate-resolve). Additionally, there's an open issue on the Wasp GitHub repository that discusses running prisma migrate deploy as a step before deployment, rather than as part of the deployed Docker container. This might be relevant to your situation. You can find the discussion here (https://github.com/wasp-lang/wasp/issues/215). Please note that these steps involve direct manipulation of your production database, so proceed with caution. Always ensure you have a backup of your data before making any changes. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mb23, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
mb23
mb23OP•3mo ago
@kapa.ai How can I access the Prisma database? Wasp only offers a limited set of options for wasp db, no?
MEE6
MEE6•3mo ago
Wohooo @mb23, you just became a Waspeteer level 4!
kapa.ai
kapa.ai•3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, you're correct. Wasp does provide a limited set of commands for interacting with the database, primarily executing Prisma commands behind the scenes. These commands include wasp db migrate-dev for synchronizing the development database with the current state of the schema, and wasp db studio for opening the GUI for inspecting your database (source (https://wasp-lang.dev/docs/general/cli#database-commands)). However, if you need more control, you can directly interact with Entities by importing and using the Prisma Client. This is recommended only if you need a feature Wasp doesn't provide. Here's an example of how you can use the Prisma Client in your Wasp server code:
import { prisma } from 'wasp/server'

prisma.task.create({
description: "Read the Entities doc",
isDone: true // almost :)
})
import { prisma } from 'wasp/server'

prisma.task.create({
description: "Read the Entities doc",
isDone: true // almost :)
})
(source (https://wasp-lang.dev/docs/data-model/entities#working-with-entities)) There's also an open issue on the Wasp GitHub repository discussing the possibility of giving direct access to Prisma CLI/commands through the Wasp CLI. You can follow the discussion here (https://github.com/wasp-lang/wasp/issues/216). Lastly, if you're trying to interact with your database after deployment, you might find this Discord thread (https://discord.com/channels/686873244791210014/1220423321422663820) helpful. It discusses how to connect to your production database and interact with it using wasp db studio. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mb23, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
mb23
mb23OP•3mo ago
I have fixed this issue by removing the entry for the failed migration in the database in Railway and re-deploying the whole thing
miho
miho•3mo ago
Nice job fixing it! That's what I wanted to suggest 🙂 Deleting the entry in _migrations table in the production DB is the way to go.
mb23
mb23OP•3mo ago
Thanks for your response @miho !
Want results from more Discord servers?
Add your server