Skip to content

Cannot migrate models not attached to this datasource: Application #2073

@margagn

Description

@margagn

I just followed the following tutorial (https://docs.strongloop.com/display/public/LB/Connect+your+API+to+a+data+source) and I was able to see the CoffeeShop table in my SQL Server Express 2014. However, as soon as I change the dataSource for the built-in models (User, Application, etc.) I get the following error: "Cannot migrate models not attached to this datasource: Application".

Any idea what is going on?

Thank you!

create-sample-model.js

module.exports = function(app) {

  app.dataSources.sqlserver.automigrate(['User', 'Application', 'Role', 'ACL', 'RoleMapping', 'AccessToken'], function(err) { 
    if (err) throw err;
  });

  app.dataSources.sqlserver.automigrate('CoffeeShop', function(err) {
    if (err) throw err;

    app.models.CoffeeShop.create([
      {name: 'Bel Cafe', city: 'Vancouver'},
      {name: 'Three Bees Coffee House', city: 'San Mateo'},
      {name: 'Caffe Artigiano', city: 'Vancouver'},
    ], function(err, coffeeShops) {
      if (err) throw err;

      console.log('Models created: \n', coffeeShops);
    });
  });
};

model-config.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "sqlserver"
  },
  "AccessToken": {
    "dataSource": "sqlserver",
    "public": false
  },
  "ACL": {
    "dataSource": "sqlserver",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "sqlserver",
    "public": false
  },
  "Role": {
    "dataSource": "sqlserver",
    "public": false
  },
  "CoffeeShop": {
    "dataSource": "sqlserver"
  }
}

datasources.json

{
  "sqlserver": {
    "host": "MyMachine",
    "database": "demo",
    "username": "User",
    "password": "password",
    "name": "sqlserver",
    "connector": "mssql",
    "debug": true,
    "options": {
      "encrypt": false,
      "instance": "SQLEXPRESS"
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions