2
votes

I'm referring below link to set up loopback framework and to create simple APIs

https://docs.strongloop.com/display/public/LB/Getting+started+with+LoopBack

But I'm getting following error when I tried to connect my API to datasourcenot getting what is the reason and how to resolve it. Please anyone can help me in resolving this.

Error: Cannot migrate models not attached to this datasource: CoffeeShop
    at /Users/emotian/Development/loopback-getting-started/node_modules/loopback-datasource-juggler/lib/datasource.js:822:14
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickDomainCallback (node.js:390:13)
    at process.fallback (/Users/emotian/Development/loopback-getting-started/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:450:15)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3
1
Have you done this step? That error says, that you are trying to create some instances of your CoffeeShop model, but it doesn't know where to store them. - Ivan Schwarz
It sounds like you do not have MySQL or any DB running that it can connect to. The easiest way to test this is to just use Strongloop demo database. They provide instructions how to connect to it under the heading Configure datasource. Make sure your internet connection works of course as well to avoid other spurious errors. - Faktor 10
I have the same problem now. Can somebody check the tutorials? Many things are not working as written. I have everything like on the tutorial. New datasource created, I was using apic CLI. Grr i hate it so much! - Erik Bors

1 Answers

0
votes

Make sure you add the datasource first and then install the connector.

lb datasource mysqlDb
npm install --save loopback-connector-mysql

check server/datasources.json if everything's correct

delete the old models/coffeeshop.js/json just in case

then run

lb model

and select the new datasource and add desired fields.