PSQL:错误:关系不存在

时间:2017-04-07 00:39:47

标签: javascript node.js postgresql express

当我从我的数据库使用Express获取请求时出现错误,我不确定这意味着什么。以下是错误的简短形式:

{错误:关系“电影”不存在     在Connection.parseE

这是我的代码(server.js):

var express = require('express');
var bodyParser = require('body-parser');
var knex = require("./db/knex");
var movies = require('./routes/movies.js');
var actors = require('./routes/actors.js');
var roles = require('./routes/roles.js');
var app = express();
var port = process.env.PORT || 8000;

// body parser
app.use(bodyParser.json());

// router
// get all
app.get("/movies", movies.getAllMovies);

app.listen(port, function() {
  console.log("Now listening on port " + port);
});

模块(movies.js):

var knex = require("../db/knex");

// get all
var getAllMovies = function(req, res) {
  knex.raw('SELECT * FROM movies')
  .then(function(movies) {
    res.send(movies.rows);
  }).catch(function(err) {
    console.log(err);
  });
}

module.exports = {
   getAllMovies:getAllMovies,
   getOneMovie:getOneMovie,
   postMovie:postMovie,
   putMovie:putMovie,
   deleteMovie:deleteMovie
 }

如果您能找到错误,请告诉我!

1 个答案:

答案 0 :(得分:1)

我实际上已经明白了。所有变量和表都很好,但我的一个knex配置文件没有连接到正确的数据库。

原件:

module.exports = {
      development: {
          client: 'pg',
          connection: 'postgres://localhost/stores', // ** WRONG **
          migrations: {
              directory: __dirname + '/db/migrations',
            },
          seeds: {
              directory: __dirname + '/db/seeds',
            },
        },
 }

第4行应阅读:

connection: 'postgres://localhost/movies_and_actors'