gpt4 book ai didi

javascript - PSQL : error: relation does not exist

转载 作者:行者123 更新时间:2023-11-29 12:55:58 27 4
gpt4 key购买 nike

当我从数据库中使用 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
}

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

最佳答案

我真的想通了。所有变量和表格都很好,但我的一个 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'

关于javascript - PSQL : error: relation does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267897/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com