Search code examples
node.jsloopbackjsstrongloop

Cannot migrate models not attached to this datasource


I tried to create tables from models using code in server.js:

app.datasources['Billing'].automigrate(['Roles', 'Users'], function(err) {
   console.log(err);
});

and got the following error:

[Error: Cannot migrate models not attached to this datasource: Roles Users ]

Indeed I'm not sure which way node creates tables in mysql db but this solution was provided in manual.

Probably someone has a link to any documentation regarding this issue.


Solution

  • Like error message suggests, your models are not attached to "Billing" datasource. Use attachTo() to assign datasource to a model.

    app.models.YourModel.attachTo(app.dataSources.Billing);
    

    Also this answer might be helpful