Laravel string data, right truncated: 1406 Data too long for column

mafortis

I have pivot table post_tags which will store id of post and id of tag

PS: all my tables using uuid.

Now when I try to add/change my post tags in update function it returns this error:

message: "SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'tag_id' at row 1 (SQL: insert into `post_tags` (`id`, `post_id`, `tag_id`) values (d0fb529e-38ac-4197-9455-e41898de9d05, c4a41a90-1274-4830-8974-71d6b5834216, bd89cf45-bb85-4e4b-93f8-342e86dbaa31,9adc54df-e778-432d-be25-282169a7c5af))"

Code

//.....
$post->save();
$tags_id = (array) $request->input('tags');
foreach( $tags_id as $tag_id ) {
  $tag_data_to_sync[ $tag_id ] = [ 'id' => \Ramsey\Uuid\Uuid::uuid4()->toString() ];
}
$post->tags()->sync( $tag_data_to_sync );

Any idea?

mafortis

SOLVED

My tags ids came like "86198680-1f0b-4544-851a-4c39e4f7c3ec,2bbe9776-7413-43fa-9cae-3378f39f3c2d" and I had to explode my tags data in order to loop them

$tags_id = explode(',', $request->input('tags'));

Now works just fine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Laravel: String data, right truncated: 1406 Data too long for column

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'ans' at row 1 (SQL: insert into `faqs` (`title`, `ans`, `updated_at`,

Laravel Backpack Image Field Error: 1406 Data too long for column

"ERROR 1406: 1406: Data too long for column" but it shouldn't be?

MySQL ERROR 1406 (22001): Data too long for column

mysql.connector.errors.DataError: 1406 (22001): Data too long for column

MYSQL : Why a data of 10 536 bytes get error 1406 Data too long for a TEXT column max size of 65 535 bytes

How to solve django.db.utils.DataError: (1406, "Data too long for column 'product_team' at row 1")

How could I get "String or binary data would be truncated" when the value being updated is not too long?

Laravel SQLSTATE[01000]: Warning: 1265 Data truncated for column for urdu or arabic character which are RTL mean right to left

Spring Data "Data too long for column at row"

Trying to print prime numbers from 1 to 1000 separated by with &. The error is "ERROR 1406 (22001) at line 28: Data too long for column 'p' at row 1"

Data truncated for column?

Data truncated for column

Data too long for column when creating user

Doctrine: data too long for column (due to escaping)

Data too long for column error with national characters

How to fix data too long for column

String is being truncated when its too long

'PDOException' with message 'SQLSTATE[22001]: String data, right truncated: 0

Data truncation: Data too long for column 'logo' at row 1

MySQL LOAD DATA INFILE Data too long for column exception

Data truncation: Data too long for column grails GSP field

In Laravel Backpack - Column data in view details and XLS download is truncated

String Or Binary Data Would Be Truncated - Column is Big Enough

Liquibase inserting into BIT column, MySQL, data too long for column

Mysql Data too long

MySQL - Data Too Long?

MYSQL: 1265 Data truncated for column?