Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ERROR: Validation error" message when executing two Sequelize commands in "pretest" script

I'm writing tests for my project. It uses Sequelize and I thought about doing the following:

"pretest": "NODE_ENV=testing yarn sequelize db:migrate && yarn sequelize db:seed:all",
"test": "mocha --require @babel/register 'src/tests/**/*.spec.js'",
"posttest": "NODE_ENV=testing yarn sequelize db:migrate:undo:all"

But the following shows:

❯ yarn test     
yarn run v1.19.2
$ NODE_ENV=testing yarn sequelize db:migrate && yarn sequelize db:seed:all
$ /home/gabriel/Workspace/graphql-apollo/node_modules/.bin/sequelize db:migrate

Sequelize CLI [Node: 12.13.1, CLI: 5.5.1, ORM: 5.21.2]

Loaded configuration file "src/config/database.js".
== 20191123132531-create-users: migrating =======
== 20191123132531-create-users: migrated (0.047s)

== 20191123132658-create-messages: migrating =======
== 20191123132658-create-messages: migrated (0.028s)

$ /home/gabriel/Workspace/graphql-apollo/node_modules/.bin/sequelize db:seed:all

Sequelize CLI [Node: 12.13.1, CLI: 5.5.1, ORM: 5.21.2]

Loaded configuration file "src/config/database.js".
== 20191123132945-users: migrating =======

ERROR: Validation error

error Command failed with exit code 1.

If I execute the migration and seeding command separately, it works fine. I also tried to use concurrently, but the same happens.

"pretest": "concurrently 'NODE_ENV=testing yarn sequelize db:migrate' 'yarn sequelize db:seed:all'",
like image 253
fermoga Avatar asked Nov 07 '22 11:11

fermoga


1 Answers

@gamofe Add the --debug flag to the command to see more info about the error. e.g.

    $ sequelize db:seed:all --debug

It's very likely you are getting this error because you are running sequelize db:seed:all without undoing previous seed. If your table already contains the data you are trying to seed in which some of them have unique constraint, you'll hit the unique constraint error. To solve this you would need to run the sequelize db:seed:undo:all before seeding. You can find more info here https://sequelize.org/master/manual/migrations.html

like image 153
Oyedeji Peace Avatar answered Nov 14 '22 23:11

Oyedeji Peace