Migration generation error
Hey everyone, I am new to drizzle and my use case is drizzle with mysql database using plain javascript. I have gone over the Drizzle documentations, as well as posts online to tailor the implementations to my use case. When I ran the drizzle-kit migrate command, I got the error without creating the migration folder except for one time out of the many times i have ran that command.
However, i deleted the migration folder that one time it worked because i thought something went wrong and wanted to retry. But now, I just keep getting this error with no other information to work with on sorting out the issue
21 Replies
drizzle-kit migrate
only applies migrations. drizzle-kit generate
is what creates the migrationsyes... the generate command is what is giving the error without generating the migrations folder
Hi @Luxaritas , so I had assistance from a friend that makes use of an older version of the drizzle-orm and the drizzle-kit that suggested I downgrade to the version he uses just to test.
I made use of
as suggested, then attempted generation and migration without changing anything else in my code and it worked, which makes me wonder if it is a version issue.
So is it possible that either I need to update code somewhere to accommodate the latest versions of the drizzle-orm and drizzle-kit and I don't know how to do it or the latest versions might have unexpected issue not reported yet?
Hm, as far as I know that error isn’t really an error - it’s just notifying you of which config file its using. So it’s a little hard to know exactly what’s going wrong. It might help if you’re able to provide a minimum reproduction (eg in a GitHub repo)
okay... so the current code i have is in a private repo because it is for work. So maybe , what i will do is create a personal use case project and then share the code with you.
Yeah as I said, minimum reproduction - ideally you can get it down to eg a drizzle schema with like one table and one field, a package.json with drizzle-orm/drizzl-kit, and nothing else 🙂
Okay, no problem
this is the link to the repo: https://github.com/7amarah/drizzle-orm-with-mysql.git
GitHub
GitHub - 7amarah/drizzle-orm-with-mysql
Contribute to 7amarah/drizzle-orm-with-mysql development by creating an account on GitHub.
also, if I may ask, how do you close a connection to the database after each database query. I got this error today:
This is up to your DB driver, afaik drizzle doesn't manage this directly. You most likely won't want to close connections after each query though, as that adds a lot of overhead to recrete the connections on each query (typically you'll even create a connection pool which opens up a bunch of connections which stick around long-term, then as queries are executed they use available connections from the pool)
oh okay, i was asking because the drizzle documentation suggests
so I am currently using the single client connection and from what I have gathered so far online, I thought maybe the connection could have been the reason for the new error I stated that I got today
I assume that means when instantiating drizzle with the intention of using
migrate()
, use eg mysql.createConnection
rather than instantiating a connection pool
Back to this. I've cloned the repo, updated drizzle-orm and drizzke-kit to latest, then run drizzle-kit generate and get the following:Unless this is because I haven't actually spun up a mysql instance
This is odd though, I don't know why itd complain about mysql2
Ah you don't actually have to specify the driver in this case
Also, needed to change the schema path to remove
api/
Now running
drizzle-kit generate
works fineI am more inclined to agree with your last reply because it seems to be complaining about the driver
wait, you used mysql database... made no changes to the db connection file or the drizzle.config.js file and it worked
Yeah so the status is:
- with
[email protected]
and [email protected]
- with driver
removed from drizzle.config.js
- with schema
changed to "./models/schema.js"
in drizzle.config.js
Running drizzle-kit generate
worksokay let me check it out
I'll also note I'm using node v20.17.0 if that matters for some reason
i will check
oh okay... I am using node v20.14.0... so could it matter?
Shouldn't
It is hard to believe that my adding driver to the drizzle.config.js file was the main issue.
I adjusted the code to my actual project and it generated
thank you so much
Oh okay, I re-read this reply and i get now. Thank you so much