2017-06-02 23 views
-1

我有表 '客户'未处理排斥RequestError:所述nvarchar的值 '238998679919674' 的转化溢出int列

enter image description here

和表 '交谈'

enter image description here

我在JavaScript中我很新。目前,我尝试使用knex + bookshelf(带有繁琐驱动程序的SQL Server数据库)来加入这两个表。我将这两个表分成两个模型,并从路由器中调用它(我使用Node js)。

conversation.js

customer: function() { 
    return this.belongsTo('Customer','uniqueid'); 
} 

customer.js

conversation: function(){ 
    return this.hasMany('Conversation','customer_id'); 
} 

当我尝试加入表作为

Customer.fetchAll({withRelated:['conversation'], debug: true}).then(function(data{ 
    console.log('data : '+data); 
}); 

不幸的是,我总是得到错误:

Unhandled rejection RequestError: The conversion of the nvarchar value '238998679919674' overflowed an int column.

我好奇其中从来到这个错误吗?因为列的类型是nvarchar,而不是int。

的调试的结果是

{ method: 'select', 
    options: {}, 
    timeout: false, 
    cancelOnTimeout: false, 
    bindings: [], 
    __knexQueryUid: '7befdc84-c66c-4278-b88c-d53a306c36db', 
    sql: 'select [customers].* from [customers]' } 
GET /ticket/list 500 16 - 21.899 ms 
{ method: 'select', 
    options: {}, 
    timeout: false, 
    cancelOnTimeout: false, 
    bindings: 
    [ 1, 
    2, 
    3, 
    4, 
    5, 
    6, 
    7, 
    8, 
    9, 
    10, 
    11, 
    12, 
    13, 
    14, 
    15, 
    16, 
    17, 
    18, 
    19, 
    20, 
    21, 
    22, 
    23, 
    24, 
    25, 
    26, 
    27, 
    28, 
    29, 
    30, 
    31, 
    32, 
    33, 
    34, 
    35, 
    36, 
    37, 
    38, 
    39, 
    40, 
    41, 
    42, 
    43, 
    44, 
    45, 
    46, 
    47, 
    48, 
    49, 
    50 ], 
    __knexQueryUid: '29ca9239-b7af-4765-95b1-836ed2c570ce', 
    sql: 'select [conversations].* from [conversations] where [conversations].[customer_id] in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' } 
+0

你可以调试你的代码,并找到一个坏行 –

+0

我编辑的帖子,并把调试的结果 – Akmal

回答

0

你尝试加入客户ID两个表,对不对?在第一个表(customers)中id是int,在第二个customer_id中是nvarchar。将int连接到nvarchar时,nvarchar将转换为int,但int数据类型的最大可接受值为2,147,483,647,列conversations.customer_id的值为'238998679919674',无法将其转换为int,这就是错误所说的内容。 你可以尝试加入你的表不是

customers.id = conversations.customer_id 

cast(customers.id as nvarchar(255) = conversations.customer_id 

,但有一个逻辑错误:不是所有的conversations.customer_id有记者customers.id,所以或许加盟是不正确的

相关问题