SnakesCantWearBoots
SnakesCantWearBoots

Reputation: 367

Error on connection between LoopbackJS and PostgreSQL when making a request

I instaled postgresql and set up a new user and made a new database with tables that I needed. Also I instaled loopback and setup an API server. Connected the API and the database via loopback-connector-postgresql. And when I go to localhost:3000/explorer and try to make a get request I get an error "message": "relation \"public.acl\" does not exist" . I tried to search this error, with no luck, I am new to Loopback JS. Here is the full error:

{
  "error": {
    "statusCode": 500,
    "name": "error",
    "message": "relation \"public.acl\" does not exist",
    "length": 109,
    "severity": "ERROR",
    "code": "42P01",
    "position": "93",
    "file": "parse_relation.c",
    "line": "1159",
    "routine": "parserOpenTable",
    "stack": "error: relation \"public.acl\" does not exist\n    at Connection.parseE (C:\\Users\\Adomas\\Documents\\ActualDocs\\Projects\\ReminderApp\\node_modules\\pg\\lib\\connection.js:553:11)\n    at Connection.parseMessage (C:\\Users\\Adomas\\Documents\\ActualDocs\\Projects\\ReminderApp\\node_modules\\pg\\lib\\connection.js:378:19)\n    at Socket.<anonymous> (C:\\Users\\Adomas\\Documents\\ActualDocs\\Projects\\ReminderApp\\node_modules\\pg\\lib\\connection.js:119:22)\n    at emitOne (events.js:116:13)\n    at Socket.emit (events.js:211:7)\n    at addChunk (_stream_readable.js:263:12)\n    at readableAddChunk (_stream_readable.js:250:11)\n    at Socket.Readable.push (_stream_readable.js:208:10)\n    at TCP.onread (net.js:597:20)"
  }
}

Upvotes: 2

Views: 1087

Answers (1)

Sashi
Sashi

Reputation: 2867

I believe the problem is because you could not create the database tables for loopback's build in models. ACL is one of them.

You could follow the instructions on this link

Copy pasting the text here so it is easy for you to find

To create tables for LoopBack built-in models, follow this procedure:

  1. Follow the basic procedure in Attaching models to data sources to change from the in-memory data source to the database you want to use.

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

    var server = require('./server'); 
    var ds = server.dataSources.db; 
    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(); 
    }); 
    
  3. Run the script manually:

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

Upvotes: 4

Related Questions