尝试插入外键时产生500错误

时间:2018-12-04 15:13:44

标签: sequelize.js

我有一个联接表ManufacturerTab。当我尝试插入外键值manufacturerId: 1tabsTemplateId: 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);  
  });  
});

0 个答案:

没有答案