Vanessa Kroeker
07/18/2022, 8:01 PMprisma migrate dev
) after squashing migrations.
Here's what I'm doing:
1. Squash migrations (following Prisma's guide on squashing migrations to create a clean history in a production environment: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/squashing-migrations#how-to-create-a-clean-his[…]-a-production-environment), including marking the migration as applied
2. Make a change to schema.prisma
3. Run prisma migrate dev
to create a new migration
4. Make another change to schema.prisma
5. Run prisma migrate dev
to create another new migration
6. Migration fails with following error:
Error: P3006
Migration `20220718195944_migration_name` failed to apply cleanly to the shadow database.
Error code: P1014
Error:
The underlying table for model `users` does not exist.
The same thing will happen if I run the first migration generation after squashing with `--create-only`: when I then subsequently try to run prisma migrate dev
to apply the created migration, the same error message as above will come up.
Creating/applying these migrations works fine as long as the previous migrations haven't been squashed. This is only happening after squashing. So I understand that I can revert back to the pre-squashed migration history and reset from there, but if squashing migrations is an option - and it's one we want to use - it shouldn't block further migrations from being created and applied.
Any help/advice is greatly appreciated, thank you!
UPDATE: This only happens when following the documented instructions for creating a clean history in a production environment, ie. by creating the squashed_migrations
directory with the following command
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel ./prisma/schema.prisma \
--script > ./prisma/migrations/squashed_migrations/migration.sql
rather than creating it by running prisma migrate dev --name squashed_migrations
.tom
07/19/2022, 3:56 AMmigrate dev
), after you squashed your migrations and accepted a reset from migrate dev, right?
One thing to keep in mind is that the migrations in ./prisma/migrations
are executed in lexicographic order, so if you keep the default generated names, any migration in a directory starting with a number (the timestamps) will come before squashed_...
, so I think what you may be seeing is your migrations running in the wrong order (that would explain why your next migration fails on a missing table). Does that sound possible?
Regardless, we have to fix the docs to use something like 000000_squashed_migrations
instead of squashed_migrations
as a directory name.tom
07/19/2022, 10:57 AM