balmasi / migrate-mongoose

A node based migration framework for mongoose supporting ES6 migrations
MIT License
262 stars 83 forks source link

Schema hasn't been registered #79

Open PrinceCEE opened 2 years ago

PrinceCEE commented 2 years ago

When running the migrate up command, it consoles that schema hasn't been registered for my models, whereas I imported the schema, and used mongoose.mode to create the model.

vsmeyukha commented 2 years ago

You have to import the schema to migration file and then write directly in up function smth like this:

const model = this('model', Model.schema)

After that use this model and it seems to work well.

It happens because migrate-mongoose and the model use different instances of mongoose connection. And that means that the model isn't connected yet when the migrator is. That's why the migrator doesn't see the model if you don't write thing that I've mentioned above.