Hey! I have a question regarding migration managem...
# orm-help
d
Hey! I have a question regarding migration management. I've been tinkering with the database locally and reseted it to apply some migrations. My app consists of self hosted postgres on Digital Ocean + prisma&next running on vercel. Now my production database refuses to migrate due to obvious reasons:
Copy code
10:54:13.919  	Error: P3018
10:54:13.919  	A migration failed to apply. New migrations can not be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
10:54:13.919  	Migration name: 20210904075303_add_new_heats_structure
10:54:13.919  	Database error code: 23502
10:54:13.919  	Database error:
10:54:13.919  	Database error
10:54:13.919  	Null constraint failed: (property)
10:54:13.919  	   0: migration_core::api::ApplyMigrations
10:54:13.919  	             at migration-engine/core/src/api.rs:73
10:54:13.933  	error Command failed with exit code 1.
10:54:13.934  	info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
10:54:13.950  	Error: Command "yarn run vercel-build" exited with 1
First question: what would be the correct way to resolve this in two cases: 1. if I care about the data 2. if I don't care if data is lost(this is the case now, but in the future I bet it could be different) Shall I just drop the database and redeploy on vercel? Or there is some prisma magic command that could help me
r
@Dimitri Ivashchuk 👋 The basic workflow in this case would be to not reset the database and tinker with the migrations on development. To keep a consistent and easy path, creating the migrations using
migrate dev
and applying them on production using
migrate deploy
is the way to go. As for resolving the current case, 1. If you care about the data, try baselining your production database to match the state of your development one. 2. If you don’t care, then simply running
prisma migrate reset
should do it.
d
Hey Ryan! thanks a lot for the response
so if I create non NULL fields which prompts me to reset the database locally what should I generally do
create migration with --create-only and then adjust the migration file so it does not break the state of the local db => which it turn won't break the state of the prod db as they are in sync
am I thinking in the right direction?
r
Non-null fields cannot be added directly on a table with existing data. You need to do the following in two migrations: 1. Create a nullable field and Seed that field with the relevant data 2. Make it non-nullable
d
aha, interesting
thanks!
👍 2