Prisma migrations with old database getting issues.

Hey guys, we have a very large database, and we have done prisma db pull to pull down the structure into the schema.prisma file, and then we started moving stuff into a multi-file schema structure, nothing has been deleted/removed, just moved around. Currently though, when we do: prisma migrate dev it's telling us there are loads of missing tables, for context prisma generate is correct, and has all the existing tables, nothing is lost. But for some reason, asking prisma to migrate causes it to, essentially, not see the tables because they are in different folders? The configuration is correct and the multi-file stuff is correct as generate works... so unsure what is happening here?
2 Replies
Prisma AI Help
Prisma AI Help23h ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. It sounds like your multi-file Prisma schema is set up correctly for prisma generate (since the client sees all tables), but prisma migrate dev is not recognizing all tables and reports missing tables after moving to the multi-file structure. Based on the knowledge sources, here are some key points and troubleshooting steps: 1. Schema Directory Configuration: For multi-file schemas, you must point Prisma CLI to the directory containing all .prisma files (not just the main file). This can be done via the --schema CLI flag, the prisma.schema field in package.json, or the schema property in prisma.config.ts. Make sure you are pointing to the folder, not a single file. For example:
// package.json
{
"prisma": {
"schema": "./prisma"
}
}

// package.json
{
"prisma": {
"schema": "./prisma"
}
}

or in prisma.config.ts:
export default {
schema: path.join('prisma'),
}

export default {
schema: path.join('prisma'),
}

Multi-file Prisma schema docs 2. Migrations Folder Placement: The migrations directory must be at the same level as the .prisma file that defines the datasource block. If you move your models into a subfolder (e.g., prisma/models), keep schema.prisma and migrations in the root prisma directory. If the migrations folder is inside the models folder or not at the correct level, migrations may not be picked up correctly source. 3. Common Pitfall: If you set --schema=prisma but have your migrations folder in prisma/migrations, Prisma may ignore the migrations folder. The correct structure is:
prisma/
migrations/
schema.prisma
models/
user.prisma
...

prisma/
migrations/
schema.prisma
models/
user.prisma
...

source 4. Resetting and Baselining: If you have an existing database, you may need to use the [baselining workflow](https://github.com/prisma/prisma/d iscussions/26085) to align your migration history with the current state of the database, especially if you see drift errors. Summary:
Check that your schema directory and migrations folder are correctly configured and at the right levels. If the structure is correct and the issue persists, consider using the baselining workflow to sync migration history. If you follow these steps and still have issues, there may be a bug or edge case—see the linked issues for more context. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
DeathlyNocturnal
DeathlyNocturnalOP23h ago
We have already done that, because we did the db pull to baseline it, so I think you have a bug somewhere.

Did you find this page helpful?