loopback-example-database icon indicating copy to clipboard operation
loopback-example-database copied to clipboard

Schema discovery, Error: Table 'Account' does not exist.

Open AhtiAhde opened this issue 9 years ago • 3 comments

For some reason, the automigrate.js will work just fine, but the discover-schema.js is not able to find the table, even though it exists in mysql command-line cli and works just fine with the localhost/explorer.

What could be the reason for this?

Full trace: at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/datasource.js:1487:10 at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:3694:9 at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:359:16 at iteratorCallback (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:935:13) at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:843:16 at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:3691:13 at apply (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:21:25) at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/node_modules/async/dist/async.js:56:12 at /home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/observer.js:250:22 at doNotify (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/observer.js:155:49) at MySQL.ObserverMixin._notifyBaseObservers (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/observer.js:178:5) at MySQL.ObserverMixin.notifyObserversOf (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/observer.js:153:8) at cbForWork (/home/ubuntu/workspace/mysql-test/node_modules/loopback-datasource-juggler/lib/observer.js:240:14) at /home/ubuntu/workspace/mysql-test/node_modules/loopback-connector/lib/sql.js:643:7 at handleResponse (/home/ubuntu/workspace/mysql-test/node_modules/loopback-connector-mysql/lib/mysql.js:193:17) at Query._callback (/home/ubuntu/workspace/mysql-test/node_modules/loopback-connector-mysql/lib/mysql.js:204:7)

AhtiAhde avatar Sep 13 '17 08:09 AhtiAhde

Resolved:

The schema parameter of discoverSchema must match database name, instead of project name. This surprised me, since I was assuming, that the database name is taken from the datastore.database property.

I also discovered something, which might be considered as a bug or at least a design flaw.

If I use database name of another database, that is not affiliated with the datastore, I can still write it. I would think, that it would be much safer and more practical, if the schema property would not override the database of the datastore to another database.

Of course I understad, if the intended usage of datastores in some cases would be fit as a plain connector without associated database and only be used with schema parameters for database selection.

It would be nice, that in case of datastore object has a database property with a valid value, it would use that database and not care about the schema parameter (perhaps allow it for override purposes, if such use case exists, but otherwise it should be redundant). Now I have to write this if I want to avoid hard-coding database names and exposing bugs in case I change the dataase name associated with the datastore:

var ds = app.datasources.test;
ds.discoverSchema('Account', {schema: ds.database}, function(...){...})

AhtiAhde avatar Sep 13 '17 09:09 AhtiAhde

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 12 '17 10:11 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Nov 26 '17 11:11 stale[bot]