我有一个联接表ManufacturerTab
。当我尝试插入外键值manufacturerId: 1
和tabsTemplateId: 1
时,出现500错误:
{
"name": "SequelizeDatabaseError",
"parent": {
"name": "error",
"length": 267,
"severity": "ERROR",
"code": "23502",
"detail": "Failing row contains (24, 2018-12-04 14:46:43.183+00, 2018-12-04 14:46:43.183+00, null, null).",
"schema": "public",
"table": "ManufacturerTabs",
"column": "manufacturerId",
"file": "execMain.c",
"line": "2008",
"routine": "ExecConstraints",
"sql": "INSERT INTO \"ManufacturerTabs\" (\"id\",\"createdAt\",\"updatedAt\") VALUES (DEFAULT,'2018-12-04 14:46:43.183 +00:00','2018-12-04 14:46:43.183 +00:00') RETURNING *;"
},
"original": {
"name": "error",
"length": 267,
"severity": "ERROR",
"code": "23502",
"detail": "Failing row contains (24, 2018-12-04 14:46:43.183+00, 2018-12-04 14:46:43.183+00, null, null).",
"schema": "public",
"table": "ManufacturerTabs",
"column": "manufacturerId",
"file": "execMain.c",
"line": "2008",
"routine": "ExecConstraints",
"sql": "INSERT INTO \"ManufacturerTabs\" (\"id\",\"createdAt\",\"updatedAt\") VALUES (DEFAULT,'2018-12-04 14:46:43.183 +00:00','2018-12-04 14:46:43.183 +00:00') RETURNING *;"
},
"sql": "INSERT INTO \"ManufacturerTabs\" (\"id\",\"createdAt\",\"updatedAt\") VALUES (DEFAULT,'2018-12-04 14:46:43.183 +00:00','2018-12-04 14:46:43.183 +00:00') RETURNING *;"
}
POST请求:
http://localhost:3000/manufacturers/1/manufacturer-tabs
BODY JSON:
{
"manufacturerId": 1,
"tabsTemplateId": 1
}
路线
/* Add Manufacturer Tab */
router.post('/', function(req, res) {
models.ManufacturerTab.create({
manufacturerId: req.body.manufacturerId,
tabsTemplateId: req.body.tabsTemplateId
}).then(function(manufacturer_tab) {
res.status(200).json(manufacturer_tab);
}, function(error) {
res.status(500).send(error);
});
});