简体   繁体   English

不允许从数据类型varchar(max)隐式转换为varbinary(max)。 使用CONVERT函数运行此查询

[英]Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query

I'm using MySQL in development, storing base64 image in longblob data type. 我在开发中使用MySQL,以longblob数据类型存储base64图像。

But I'm getting error below when trying to insert data after I changed database to MS SQL & data type to varbinary(max) 但是在将数据库更改为MS SQL并将数据类型更改为varbinary(max)后尝试插入数据时,出现以下错误

Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. 不允许从数据类型varchar(max)隐式转换为varbinary(max)。 Use the CONVERT function to run this query 使用CONVERT函数运行此查询

So I put a mutator to get this around as below, 所以我放了一个变幅器来解决这个问题,如下所示

public function setItemPictureAttribute($value)
{
    $this->attributes['item_picture'] = DB::raw('CONVERT(VARBINARY(MAX), "'. $value .'")');
}

but I'm getting error below when trying to store the base64 image; 但是在尝试存储base64图像时出现以下错误;

The identifier that starts with '/9j/4QxnRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAMAAAExAAIAAAAeAAAAcgEyAAIAAAAUAAAAkIdp' is too long. 以'/ 9j / 4QxnRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAMAAAExAAIAAAAAAAAAAAAAgEyAAIAAAAUAAAAAAAkIdp'开头的标识符太长。 Maximum length is 128` 最大长度为128`

What did I miss? 我错过了什么?

EDIT: Somehow I got this work after I changed to $this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')"); 编辑:在更改为$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");之后,我以某种方式得到了这项工作$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')"); ; ; notice that I switched the double quote with single quote and vice versa in DB::raw . 注意,我在DB::raw中将双引号切换为单引号,反之亦然。 Maybe someone can explain why 也许有人可以解释为什么

Somehow I got this work after I changed to 我以某种方式获得这份工作后

$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");; 

notice that I switched the double quote with single quote and vice versa in DB::raw . 注意,我在DB::raw中将双引号切换为单引号,反之亦然。 Maybe someone can explain why 也许有人可以解释为什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - Error : Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query OPENROWSET-不允许从数据类型varchar隐式转换为varbinary(max)。 使用CONVERT函数运行此查询 - OPENROWSET - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query [SQL Server]不允许从数据类型nvarchar(max)到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - [SQL Server]Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query 不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT INSERT查询错误:不允许从数据类型varchar到varbinary的隐式转换。 使用CONVERT函数运行此查询。 - INSERT query error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. 不允许从数据类型sql_variant隐式转换为varbinary(max)。 使用CONVERT函数运行此查询。 ASP.NET SQL数据源 - Implicit conversion from data type sql_variant to varbinary(max) is not allowed. Use the CONVERT function to run this query. ASP.NET SQL DataSource 不允许从数据类型ntext到varchar的隐式转换。 使用CONVERT函数运行此查询 - Implicit conversion from data type ntext to varchar is not allowed. Use the CONVERT function to run this query 不允许从数据类型varchar到varbinary(max)的隐式转换 - Implicit conversion from data type varchar to varbinary(max) is not allowed 不允许从数据类型 varchar 到 varbinary 的隐式转换。 (SQL) - Implicit conversion from data type varchar to varbinary is not allowed. (SQL) 不允许从数据类型datetime到int的隐式转换错误。 使用CONVERT函数运行此查询 - Error of Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM