简体   繁体   English

PSQL:错误:关系不存在

[英]PSQL: error: relation does not exist

I am getting an Error when I do a get request with Express from my database and I am not sure what it means. 当我从数据库中对Express进行获取请求时,出现了错误,我不确定这意味着什么。 Here is a short form of the error: 这是错误的简短形式:

{ error: relation "movies" does not exist at Connection.parseE {错误:Connection.parseE中不存在“电影”关系

Here is my code (server.js): 这是我的代码(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);
});

Module (movies.js): 模块(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
 }

Please let me know if you can find the error! 如果您能找到错误,请告诉我!

I actually figured it out. 我真的想通了。 All the variables and tables were fine, but one of my knex configuration files was not connected to the correct database. 所有变量和表都很好,但是我的knex配置文件之一未连接到正确的数据库。

Original: 原版的:

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

Line 4 should have read: 第4行应显示为:

connection: 'postgres://localhost/movies_and_actors'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PSQL 服务器,通过 Postman 发送请求时“关系不存在” - PSQL server, 'relation does not exist' when sending a request through Postman 续集错误:关系不存在 - Sequelize Error: Relation does not exist PSQL + javascript 服务器,从 Postman 发送请求时“关系不存在” - PSQL + javascript server, 'relation does not exist' when sending a request from Postman TypeORM - 更新多对多关系抛出列不存在错误 - TypeORM - updating many to many relation throws column does not exist error 未处理的拒绝 SequelizeDatabaseError:关系“用户”不存在 - Unhandled rejection SequelizeDatabaseError: relation "users" does not exist 使用书架ORM nodejs在postgres中插入数据,由于关系不存在而出错 - Inserting data in postgres with bookshelf ORM nodejs, getting error as relation does not exist postgreSQL错误:“约束不存在”(但确实存在……) - postgreSQL error: “constraint does not exist” (but it does exist…) Postgresql 列存在,但获取关系列不存在 - Postgresql column exists, but getting column of relation does not exist SequelizeDatabaseError:Koa.js 框架中不存在关系“用户” - SequelizeDatabaseError: relation "users" does not exist in Koa.js framework 如果套接字不存在,则会发生错误回调 - Error Callback if socket does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM