Existing MySQL to Postgres
Hi everyone!
I'm planning to migrate my old MySQL database to PostgreSQL. I used pgloader to transfer all the data—no issues there. I also adjusted my schema to be compatible since there were some differences. However, when I run prisma migrate, I keep getting errors.
The only solution I’ve found so far is to reset my migrations, but that would wipe all my data. Is there any way to avoid that? What should I do?
Thanks in advance!
5 Replies
You selected the bot's instantaneous insights. Let me compile your answer right away!
Based on the knowledge sources provided, I can offer some guidance on how to handle your situation without resetting your database and losing data. This process is called "baselining" in Prisma terminology.
To avoid resetting your database and losing data when migrating from MySQL to PostgreSQL, you can follow these steps:
1. Create an initial migration that represents your current database state without applying it:
2. After this, run
npx prisma migrate dev
. It should indicate that everything is in sync.
3. You should also manually add a lock file in prisma/migrations/migration_lock.toml
with the following content:
This approach allows you to baseline your existing PostgreSQL database without resetting it and losing data. It tells Prisma Migrate to assume that the initial migration has already been applied, so it won't try to create tables that already exist.
For more detailed information on baselining, you can refer to the Prisma documentation on baselining.
If you encounter any issues during this process or need further clarification, please don't hesitate to ask for more specific guidance.
Github Issue Comment
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.What errors do you get?
Can you share them?
The first step works fine, and I have no problem, but when I move on to the second one to apply the migration, it shows me this message again.
And I also get several supposed changes.
Hastebin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
GitHub
Drift detected on first migration after using migrate diff on exist...
Bug description I am attempting to add Prisma 4.16 to an existing project (it used to use Prisma 2.12 ) on a MacBook Pro with an M1 Pro chip. During the upgrade process, I am encountering an issue ...