kareemhossam
kareemhossam

Reputation: 83

Loopback Model discovery from PostgreSQL error

I am currently building a loopback project and I need to discover existing data in a PostgreSQL database to make my models, I have successfully created the models by following the tutorial found in the docs: https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html#discover-and-save-model-definitions , but when I run GET method for any model I get an error that says

relation "public.acl" does not exist

can anyone help me fix this issue, Thanks in Advance.

Upvotes: 1

Views: 308

Answers (2)

kareemhossam
kareemhossam

Reputation: 83

Thanks @Marvin, i solved the problem by running this auto update script in ./server/boot/migrateTables.js :

'use strict';

module.exports = migrateTables;

function migrateTables(server) {
  var storage = server.datasources.db;

  storage.autoupdate();
}

Upvotes: 2

Marvin Irwin
Marvin Irwin

Reputation: 1010

You have told loopback to use your database for authentication. Loopback is asking for a table to authenticate each request which does not exist. This has nothing to do with auto migration. The following is how you can easily create the tables you need.

Loopback automigration script

Create server/create-lb-tables.js file with the following:

var server = require('./server');
var ds = server.dataSources.MYDATABASE;
var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
ds.automigrate(lbTables, function(er) {
  if (er) throw er;
  console.log('Loopback tables [' + lbTables + '] created in ', ds.adapter.name);
  ds.disconnect();
});

Run the script manually:

$ cd server
$ node create-lb-tables.js

Upvotes: 2

Related Questions