【发布时间】:2018-08-06 15:30:46
【问题描述】:
我在 knex 中使用了 reactjs、nodejs、express 和 postgress
这是代码
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))
})
我收到并出错
错误:整数的无效输入语法:“”在 Connection.parseE,在 Connection.parseMessage,在 Socket,
这是我的反应应用程序中的代码
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))
}
我试图在邮递员中测试我的终点并且它有效,idk 当我在我的反应应用程序中尝试时它说错误:整数的输入语法无效:“”
这是数据库
CREATE TABLE users (
id serial primary key,
name VARCHAR(100),
email text unique not null,
stories bigint default 0,
joined timstamp not null
);
这是我的餐桌故事
CREATE TABLE users (
id_book serial primary key,
entry bigint default 0,
title varchar(100),
category varchar(100),
description varchar(100),
mature varchar(10)
);
我想要的是故事和条目相同,我无法弄清楚 postgress 节点中的错误
【问题讨论】:
标签: node.js reactjs postgresql