Sequelize-cli db:drop and dp:create not working

35 Views Asked by At

I'm trying to docker compose up a test version of a node.js app, and using sequelize-cli commands to create/migrate/seed the mysql database.

While db:migrate works just fine (after I manually create an empty db), trying to run db:drop or db:create beforehand fails with Unhandled rejection TypeError: Cannot read property 'replace' of undefined.

In all 3 commands I am referencing the same (and correct) config file with --config <filepath> added to sequelize-cli commands and I am referencing the correct environment (indicated by logging/validating the process.env object).

I'm wondering why db:drop and db:create would behave this way if db:migrate works fine (and they're given the same config).

I am using Sequelize CLI [Node: 14.18.0, CLI: 5.5.1, ORM: 5.22.5]

1

There are 1 best solutions below

0
welew204 On

Taking a look at sequelize-cli source made it clear that these commands both required the 'database' arg to be top-level in the config object; we'd been burying those in nested objects and unpacking in production, but not in this case.

That meant the command was recieving a config with no 'database' arg, and the TypeError was simply due to trying string methods on an 'undefined' string.

So double-check your config!