To seed a database, knex says to run the following script:
$ knex seed:run
I was looking for a way to do this programmatically (ie in my javascript code). I have the following that compiles without any problems but it only returns a promise and doesn't actually do the seeding:
const knexInstance = require('knex')(config);
knexInstance.seed.run()
Any help appreciated.
Knex is using bluebird under the hood, so to run seed, you need to wait for promise to be finished.
Waiting for promise can be done by standard JavaScript await.
await knexInstance.seed.run();
Knex seed source code: GitHub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With