[英]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.