How to use Prisma migrations to add new models on an existing Laravel-managed MySQL database without data loss #28943
Replies: 3 comments 1 reply
-
|
Hey @Pavan-Kumar-KN! After you have applied have marked the baseline migration as applied via this command: What happens if you run |
Beta Was this translation helpful? Give feedback.
-
|
Hi @nurul3101, The issue I’m facing is that when I run prisma migrate dev, Prisma suggests resetting the database or running migrate reset, and also throws relation / foreign key errors—even though the current schema and database state are already in sync. Since this is a shared database with existing data, resetting the DB is not an option. I’m trying to understand the correct and safe workflow to introduce Prisma migrations without affecting the existing Laravel-managed schema. although i can push the new models using push command or deploy command but the migration file we have to maintain right |
Beta Was this translation helpful? Give feedback.
-
|
Hey @Pavan-Kumar-KN, thanks for the additional context! I understand the issue now. When you run Here's what I'd recommend:
Regarding migration files: Yes, you should maintain them! Using Let me know if you still see the reset warnings after ensuring your baseline matches the DB state exactly! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What I have done so far
The database already exists and contains data.
I created a baseline migration in Prisma that represents the current schema:
I marked the baseline migration as applied.
I updated
schema.prismaand added new models (new tables only, no changes to existing Laravel tables).When I run:
Prisma warns that:
The database will be reset, or
Data loss may occur
This is not acceptable because the database is shared and already in use.
What I want
Prisma should treat the existing schema as baseline
Prisma migrations should be used only for new tables / new models
No destructive changes
No database reset
A clean, safe workflow going forward
My Questions:
What is the correct Prisma workflow for adding new models to an already existing Laravel-managed database?
How should the baseline migration be created and applied so Prisma does not attempt a reset?
After baselining, should prisma migrate dev be used for new models, or is migrate deploy the correct command?
What is the recommended long-term migration strategy when Laravel and Prisma share the same database but Prisma is responsible for new tables?
Any official guidance or best practices for this scenario would be very helpful.
Beta Was this translation helpful? Give feedback.
All reactions