2017-06-02 5 views
-1

をオーバーフローした「顧客の未処理の拒絶RequestError:nvarchar型の値の変換 '238998679919674' は私がテーブルを持っているint型の列

enter image description here

とテーブル '会話'

enter image description here

Iかなりjavascriptで新しいです。現在、私はknex +本棚(退屈なドライバを持つSQLサーバデータベース)を使ってこれら2つのテーブルを結合しようとしています。私はこれらの2つのテーブルを2つのモデルに分けてルータから呼び出す(私はノードjを使う)。私は

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

としてテーブルを結合しようとすると

conversation.js

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

customer.js

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

残念ながら、私は常にエラーを取得:

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

エラーから来ている場所について、私は好奇心?列の型はintではなくnvarcharであるためです。

デバッグの結果は右、あなたが顧客IDに2つのテーブルを結合しようと

{ 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はintで、2番目の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を持っているので、多分は、参加します間違っています

関連する問題