2017-06-02 165 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,所以或許加盟是不正確的