{ co-6ren">
gpt4 book ai didi

node.js - postgres 错误 : invalid input syntax for integer: ""

转载 作者:行者123 更新时间:2023-11-29 13:13:42 25 4
gpt4 key购买 nike

我使用了 reactjs、nodejs、express 和 postgress with knex

这是代码

app.post('/new-story', (req, res) => {
const {title, description, mature, id} = req.body;
db.select('stories').from('users').where('id' = id)
.then(data => {
const stories = data[0].stories;
db('story')
.returning('*')
.insert({
title: title,
category: category,
description: description,
mature: mature,
entry: stories
})
.then(story => {
res.json(story)
})
})
.catch(err => console.log(err))
})

我收到错误

error: invalid input syntax for integer: "" at Connection.parseE, at Connection.parseMessage, at Socket,

这是我的 React 应用程序中的代码

onSaveDate = () => {
fetch('http://localhost:3001/new-story', {
method: 'post',
header: {'Content-Type' : 'application/json'},
body: JSON.stringify({
id: this.state.id,
title: this.state.title,
description: this.state.description,
category: this.state.category,
mature: this.state.mature
})
})
.then(response => response.json())
.then(story => console.log(story))
}

我试图在 postman 中测试我的终点并且它有效,我知道当我在我的 react 应用程序中尝试时它说错误:整数的输入语法无效:“”

这是数据库

CREATE TABLE users (
id serial primary key,
name VARCHAR(100),
email text unique not null,
stories bigint default 0,
joined timstamp not null
);

这是我的餐 table 故事

CREATE TABLE users (
id_book serial primary key,
entry bigint default 0,
title varchar(100),
category varchar(100),
description varchar(100),
mature varchar(10)
);

我想要的是 stories 和 entry 相同,我无法找出 postgress Node 中的错误

最佳答案

我得到一个错误,因为我的 id 列是空的,所以如果有人遇到像

这样的错误

error: invalid input syntax for integer: "" at Connection.parseE, at Connection.parseMessage, at Socket,

你应该检查数据库是否为空

关于node.js - postgres 错误 : invalid input syntax for integer: "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51711065/

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