W
Wasp•3w ago
jason

Accidentally cooked my db, start fresh from latest migration?

Hi all, I accidentally cooked my db again lmao, oops.. I had some migrations testing some stuff out, but accidentally really messed it up and deleted migration files by reverting with git, blah blah blah, here I am now, I THOUGHT I fixed it by running "wasp db reset" and doing a new "wasp db migrate-dev", but after changing the schema.prisma again and running "wasp db migrate-dev" again, it was saying:
Could not find the migration file at /srv/web/shelter/app/.wasp/out/db/migrations/20250414202957_video_migration/migration.sql. Please delete the directory or restore the migration file.
Could not find the migration file at /srv/web/shelter/app/.wasp/out/db/migrations/20250414202957_video_migration/migration.sql. Please delete the directory or restore the migration file.
Then I removed the empty directories from /srv/web/shelter/app/.wasp/out/db/migrations/ and ran it again, but now:
Error: P3006

Migration `20250415005503_new_init_migration` failed to apply cleanly to the shadow database.
Error:
ERROR: type "UserRole" already exists
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/lib.rs:335
1: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:276
Error: P3006

Migration `20250415005503_new_init_migration` failed to apply cleanly to the shadow database.
Error:
ERROR: type "UserRole" already exists
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/lib.rs:335
1: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:276
I'd rather just start the db fresh with no migration history, just using the current schema.primsa from my latest git commit. How can I do this?
5 Replies
MEE6
MEE6•3w ago
Wohooo @jason, you just became a Waspeteer level 4!
kapa.ai
kapa.ai•3w ago
Hi @jason. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It sounds like you're having migration issues with your Wasp project. This is a common problem when migrations get out of sync with your database. Let me help you start fresh. To completely reset your database and migrations, you should: 1. First, run wasp clean to remove all generated code and cached artifacts. If you're using SQLite, this will also delete the SQLite database Link to CLI docs. 2. Delete all existing migration files:
rm -r migrations/

rm -r migrations/

3. If you're using PostgreSQL, make sure your database is running. If you're using the built-in database, you can start it with wasp start db. 4. In a different terminal, run wasp db migrate-dev to create a fresh initial migration based on your current schema.prisma file. This approach is similar to what's recommended when migrating from SQLite to PostgreSQL, where you need to start with a clean slate Link to migration docs. If you're still experiencing issues after these steps, you might need to check if your database server is properly running and accessible. Sometimes, the error messages from Prisma can be confusing, but they often indicate that there's an issue with the database connection or schema synchronization. Remember that whenever you make changes to your entities or database configuration in your .wasp file, you need to run wasp db migrate-dev to synchronize your database schema with your code changes. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @jason, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
jason
jasonOP•3w ago
What do you mean when you say
wasp clean
wasp clean
will remove "all generated code"? Will this affect more than just the DB? nvm im about to just say screw it and run it and see what happens it worked! All good now 👍
miho
miho•3w ago
@jason thanks for the feedback, what command did you run in the end? There are: wasp db reset - drops the db and reapplies the migrations from scratch wasp clean - removes only generated code
jason
jasonOP•2w ago
wasp clean did it! I tried wasp db reset on it's own but needed to do a wasp clean to really get it right and allow me to do another migration.

Did you find this page helpful?