MySQL SQLSTATE[01000]:警告:1265 列的数据被截断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48001238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:51:49  来源:igfitidea点击:

SQLSTATE[01000]: Warning: 1265 Data truncated for column

mysqlsqllaravelrequest

提问by Honda hoda

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'pay_totals' at row 1

SQLSTATE[01000]:警告:1265 列“pay_totals”的第 1 行数据被截断

public function order(Request $req){
        $order = new Order;
        $order->pay_number = $req->checkout_number;
        $order->pay_totals = $req->checkout_total;
        $order->save();
        return redirect(route('pay'))->with('message','Sending infomation successfully');
    }

blade:

刀刃:

<input type="text" name="checkout_total" value="{{Cart::subTotal('0') }} ">

Helppp

帮助

回答by Luis felipe De jesus Munoz

The problem is that column pay_totalscan't store whatever you are getting from the input because is too big.

问题是列pay_totals无法存储您从输入中获得的任何内容,因为它太大了。

Possibles solutions

可能的解决方案

SQL:ALTER TABLE [orders] ALTER COLUMN [pay_totals] VARCHAR(MAX)

查询语句:ALTER TABLE [orders] ALTER COLUMN [pay_totals] VARCHAR(MAX)

MYSQL:ALTER TABLE [orders] MODIFY COLUMN [pay_totals] VARCHAR(60000)

MYSQL:ALTER TABLE [orders] MODIFY COLUMN [pay_totals] VARCHAR(60000)

回答by Pushpa Kumara

Same error can be occurred due data type mismatching. As an example,if you are assigning an string to float, you will get this error. so be sure to check whether the data are in correct type. I got this error on symfony.

由于数据类型不匹配,可能会发生相同的错误。例如,如果您将字符串分配给浮点数,则会出现此错误。所以一定要检查数据的类型是否正确。我在symfony上遇到了这个错误。

回答by jay thanki

Some times this error occurred due to inserting data into extra columns like ('created_at','updated_At')in pivot table. Below solution works for me.

有时由于将数据插入数据('created_at','updated_At')透视表中的额外列而发生此错误。下面的解决方案对我有用。

Error Code

错误代码

$users=User::create($input['data']);
foreach ($input['products'] as $product) {
    if (array_key_exists('special_price', $product)) {
        $userProducts[$product['id']] = ['special_price' => $product['special_price']];
    } else {
        $userProducts[$product['id']] = ['special_price' => ''];
    }
    $userProducts['created_at'] = Carbon::now()->toDateTimeString();
    $userProducts['updated_at'] = Carbon::now()->toDateTimeString();
}

//individual product with special price of each product
/*
Output before code correction

array (1 =>
array(
    'special_price' => '',
),
'created_at' => '2019-04-07 14:28:27',
'updated_at' => '2019-04-07 14:28:27',))
*/
$users->products()->sync($userProducts);

Code Correction

代码更正

$users=User::create($input['data']);
foreach ($input['products'] as $product) {
    if (array_key_exists('special_price', $product)) {
        $userProducts[$product['id']] = ['special_price' => $product['special_price']];
    } else {
        $userProducts[$product['id']] = ['special_price' => ''];
    }
    // below lines are after code correction
    $userProducts[$product['id']]['created_at'] = Carbon::now()->toDateTimeString();
    $userProducts[$product['id']]['updated_at'] = Carbon::now()->toDateTimeString();
}

//individual product with special price of each product
/*
Output after code correction

array (1 =>
array(
    'special_price' => '',
    'created_at' => '2019-04-07 14:28:27',
    'updated_at' => '2019-04-07 14:28:27',
),)
*/
$users->products()->sync($userProducts);