Loopback postgresql relation "public.acl"
Asked Answered
G

2

8

I am new to loopback and i am just started to implement the tutorial https://docs.strongloop.com/display/public/LB/Connect+your+API+to+a+data+source

But i am receiving the error:

[error: relation "public.acl" does not exist].

I searched a lot for this, but cant find the solution. Please help me to solve this. Thanks..

Grunberg answered 9/3, 2016 at 7:21 Comment(3)
Where do you receive this error ? Server startup ? Debug strings ? While making a request ?Abram
@ Overdrivr thanks man. I solved it, the solution is have to create all tables required by loopback..Grunberg
@Grunberg Not sure which answer worked for you. Could you mark the answer which worked as the right answer? Or perhaps write an answer so it is easier for anyone who might be facing the same issue? :)Phillipphillipe
H
12

As explained in the doc https://docs.strongloop.com/display/public/LB/Creating+database+tables+for+built-in+models Loopback doesn't automatically migrate (create) tables from models -- that includes built-in models.

So as the link suggests, in order to use other datasource than in-memory db, we should create a separate script server/create-lb-tables.js:

var server = require('./server');
var ds = server.dataSources.postgresDS;
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();
});

where postgresDS is the name of your datasource in server/datasources.json.

Finally, run the script to migrate the tables:

$ cd server
$ node create-lb-tables.js
Hornstein answered 17/8, 2016 at 14:40 Comment(0)
P
-1

Another to solve this problem instead of having to manually create the Tables inside postgres is to use the autoMigrate methods from the corresponding datasources.

For instance if your datasource is called storage you will have something like this :

./server/boot/migrateTables.js

module.exports = migrateTables;

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

  storage.automigrate();
}

Be careful though that you will want to disable this boot scripts once you migrated your tables since it will drop your existing database. You do it by simply commenting the first line and keep this around the corner for re-use in case you need to create to tables.

Protectionist answered 11/3, 2016 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.