What am I doing wrong with migrations?
Hey there drizzle members! So I've been trying to set up a project with NestJS using Drizzle - and while Drizzle ORM itself has been working splendildy so far, we've been having trouble with the migrations part.
We're using MySQL (mysql2 driver), trying to get the suggested
await migrate();
workflow running.
My database script looks like this:
My drizzle.config.ts is as follows:
12 Replies
When it reaches the migrate line though, it seems to fail:
Incidentally, that's the first line in the generated SQL files
So far, it has only helped to reset the DB, run drizzle-kit generate, and then it worked again. I think our understanding of the migration part might be wrong. I'd be glad to receive any tips on how to properly handle this!
Thanks in advance 👋
i run migrations manually like you said in npm scripts. example -> https://github.com/deadcoder0904/easypanel-nextjs-sqlite or any projects in my profile
i did face this error today randomly. idk why. i deleted my sqlite file & re-ran again & it worked.
i dont think that migrations re-run again if the table already exists so thats definitely a weird error as all migrations cli handle that part automatically. maybe a schema change?
I also just run migrations manually. I have a migrate.ts script and run it with bun.
i just use
node --env-file .env.production drizzle-migrate.mjs
script for now as bun windows hasn't come yet. just 7 days away so i can replace those scripts with bun too lol. or maybe wait 6 months for it to get stable.I just noticed something even more weird, when trying to bugfix one of my queries
In that error message, and in a new one I am getting (for which the code itself should be absolutely fine...), in the stacktrace, I can see it trying to access files in
But there is no such file on my filesystem. I would assume it's actually part of the Drizzle-ORM package, but I have no clue why it's logging that path.
Is there any clue on what might be causing this... ?
What package manager are you using?
Maybe it's a case of implicit dependency?
Using npm
I think the console logs with file locations aren't that important, since it's obviously finding those files
The error seems to stem from this part though:
At the part where it's trying to access col.name apparently
But I have no clue why this is happening in my update query
Ok I think I fixed my problem, it was something stupid from my side... (a small typo basically)
Which relates to another issue, is there any workaround for tables getting defined as
any
? I think I read somewhere that it's a limitation from typescript (when it comes to relations between tables), but is there some other way to "re-define" the appropriate fields of a table?Ah found it in another answer here from last year: define the callback in a references function as
AnyMySqlColumn