Help with this error. "Can't find meta/_journal.json file"

Hi guys! I am new here and recently started learning how ORMs work and started with drizzle. I built my schema and managed to successfully generate a migration file for it. However, I am unable to actually migrate this to the database. I'm getting the following error
> [email protected] db:migrate
> node drizzle/migrate.js

Error during migration: Error: Can't find meta/_journal.json file
at readMigrationFiles (backend\node_modules\drizzle-orm\migrator.cjs:52:11)
at migrate (backend\node_modules\drizzle-orm\neon-http\migrator.cjs:27:61)
at main (backend\drizzle\migrate.js:11:15)
> [email protected] db:migrate
> node drizzle/migrate.js

Error during migration: Error: Can't find meta/_journal.json file
at readMigrationFiles (backend\node_modules\drizzle-orm\migrator.cjs:52:11)
at migrate (backend\node_modules\drizzle-orm\neon-http\migrator.cjs:27:61)
at main (backend\drizzle\migrate.js:11:15)
I have checked my migrate.js file but cannot understand what the problem might be For context, I'm using the neon database server.
16 Replies
SandCat
SandCat9mo ago
Can you provide code for migrate.js ?
Apostle Tree
Apostle TreeOP9mo ago
Alright! Here's my code for migrate.js
require('dotenv').config()
const { neon } = require('@neondatabase/serverless')
const { drizzle } = require('drizzle-orm/neon-http')
const { migrate } = require('drizzle-orm/neon-http/migrator')

const sql = neon(process.env.NEON_DATABASE_URI)
const db = drizzle(sql)

const main = async () => {
try {
await migrate(db, { migrationsFolder: "migrations" })
console.log("Migration completed")
} catch (error) {
console.error("Error during migration:", error)
process.exit(1)
}
}

main()
require('dotenv').config()
const { neon } = require('@neondatabase/serverless')
const { drizzle } = require('drizzle-orm/neon-http')
const { migrate } = require('drizzle-orm/neon-http/migrator')

const sql = neon(process.env.NEON_DATABASE_URI)
const db = drizzle(sql)

const main = async () => {
try {
await migrate(db, { migrationsFolder: "migrations" })
console.log("Migration completed")
} catch (error) {
console.error("Error during migration:", error)
process.exit(1)
}
}

main()
SandCat
SandCat9mo ago
Ok it look you dont configure drizzle.config.ts also i think you dont have already generate migrations
// drizzle.config.ts
import type { Config } from "drizzle-kit";
export default {
schema: "./path-to-schema/schema.ts",
out: "./drizzle",
} satisfies Config;
// drizzle.config.ts
import type { Config } from "drizzle-kit";
export default {
schema: "./path-to-schema/schema.ts",
out: "./drizzle",
} satisfies Config;
Apostle Tree
Apostle TreeOP9mo ago
But I do have a drizzle.config.js file
SandCat
SandCat9mo ago
and where you put the out folder ?
Apostle Tree
Apostle TreeOP9mo ago
the migrations folder
drizzle.config.js
const { defineConfig } = require("drizzle-kit");
require('dotenv').config();

module.exports = defineConfig({
schema: "./drizzle/schema.js",
out: "./drizzle/migrations",
driver: "pg",
dbCredentials: {
connectionString: process.env.NEON_DATABASE_URI
},
verbose: true,
strict: true
});
drizzle.config.js
const { defineConfig } = require("drizzle-kit");
require('dotenv').config();

module.exports = defineConfig({
schema: "./drizzle/schema.js",
out: "./drizzle/migrations",
driver: "pg",
dbCredentials: {
connectionString: process.env.NEON_DATABASE_URI
},
verbose: true,
strict: true
});
SandCat
SandCat9mo ago
change this
await migrate(db, { migrationsFolder: "./drizzle/migrations" })
await migrate(db, { migrationsFolder: "./drizzle/migrations" })
You already runned this ?
"db:generate": "drizzle-kit generate:pg"
"db:generate": "drizzle-kit generate:pg"
Apostle Tree
Apostle TreeOP9mo ago
Okie one sec, i am making some schema changes. Also a doubt, is it okay to drop migrations? yes, thats how i get the .sql file and the journal file. But when I run db:migrate, it says it can't find the _journal.json file
SandCat
SandCat9mo ago
Yes because you was poiting to wrong path in migrate function
Apostle Tree
Apostle TreeOP9mo ago
Ah it works now! Although I have schema problems it seems, but the migrate is working Well, since schema.js is in the drizzle folder it self, i though simply writing migration as the pointed folder would be enough
SandCat
SandCat9mo ago
No the path is referring to where node is executed
Apostle Tree
Apostle TreeOP9mo ago
Ohh, I see. Well, it seems to be working fine now, so thnx!
SandCat
SandCat9mo ago
And just for clean architectur keep drizzle dir only for generated files , put migration script and schema in separate dir i prefere "database" dir
Apostle Tree
Apostle TreeOP9mo ago
Ah good idea. I was thinking abt it as well. Do you keep the db dir in the backend itself or create a separate dir for it(like client, db and backend)?
SandCat
SandCat9mo ago
In backend
Apostle Tree
Apostle TreeOP9mo ago
Ohh ok. Ill do that then
Want results from more Discord servers?
Add your server