Go into your schema and make the change:
NormalizedName String @unique @db.VarChar(64)
NormalizedName String? @unique @db.VarChar(64)
Then create a draft migration:
$ npx prisma migrate dev --name migration-name --create-only
Then edit the migration in SQL (this allow null values ie optional)
ALTER TABLE myTable ALTER COLUMN myColumn {DataType} NULL;
OR Postgres
ALTER TABLE myTable ALTER COLUMN myColumn DROP NOT NULL;
etc.
Then apply the modified SQL:
$ npx prisma migrate dev
I hope this works for you :)
Answer from BlaviButcher on Stack Overflownode.js - Make a change to the database with Prisma.js without having to reset the whole thing - Stack Overflow
How do I use Prisma without having to wipe my database all the time?
Why does prisma migrate dev want to reset my db?
`prisma db reset` that resets the database, pushes the schema, and runs the seed function
Go into your schema and make the change:
NormalizedName String @unique @db.VarChar(64)
NormalizedName String? @unique @db.VarChar(64)
Then create a draft migration:
$ npx prisma migrate dev --name migration-name --create-only
Then edit the migration in SQL (this allow null values ie optional)
ALTER TABLE myTable ALTER COLUMN myColumn {DataType} NULL;
OR Postgres
ALTER TABLE myTable ALTER COLUMN myColumn DROP NOT NULL;
etc.
Then apply the modified SQL:
$ npx prisma migrate dev
I hope this works for you :)
In a development environment, Prisma Migrate sometimes prompts you to reset the database. Resetting drops and recreates the database, which results in data loss. The database is reset when:
- You call
prisma migrate resetexplicitly - You call
prisma migrate devand Prisma Migrate detects drift in the database or a migration history conflict
I'm not sure why Prisma thinks that your change is breaking, but there is probably no other way to make schema change without data loss.
To recreate your database data consider using seeding script
If you are prototyping, consider using the db push command, although it will still result in data reset if Prisma considers that the change is breaking.
I'm using Prisma for a large project I've been working on for the past few months, and I still don't understand the flow of it. At first I was migrating every time I made a change to my schema, and constantly getting the "All data will be lost" prompt. Since then I've learned to use `db push` while developing and then migrate when a feature is finished, but it's still constantly making me reset my database.
Right now I'm using the same db for dev and staging (because I don't want to pay for 2 different ones) but I'd imagine this would still be an issue if I had separate databases. What do I need to do to stop being forced to reset my db? Or, at least, how would I migrate my development db to mirror my production db without it being wiped?
As you can probably tell, this is my first time working with Prisma (or any ORM, in depth) so this might be a stupid question, but I can't find much online besides general tutorials. Any help would be greatly appreciated!