Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

< GDB >'s avatar

SQLSTATE[22001] : String data too long

Good afternoon all,

I get the following error :

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'googmaps' 

I added a column to my database table where the user can insert a 'Google maps'-link. As you probably can imagine, these links tend to be long :-/

This is my migration scheme for this field:

 $table->string('googmaps')->nullable();

This is my validation in controller :

'googmaps' => ['nullable', 'active_url'],

I did not put a max of characters as a condition, but assume this error is thrown as a string has a max. length of 255 characters. (not sure if this is 100%, just how I concluded)

Is this just a matter of changing the type in my migration scheme to f.ex. text or longtext?
Or is this not really correct?

Thank you for your advice!

0 likes
8 replies
< GDB >'s avatar

@nakov Thanks for that link, so indeed just a matter of changing the type instead of string to text or medium/longtext...

Taking this into account, I saw they said :

TEXT: 65,535 characters - 64 KB 
MEDIUMTEXT: 16,777,215 - 16 MB 
LONGTEXT: 4,294,967,295 characters - 4 GB

They also say not to put a limit as a condition.

But for you as an experienced dev. do you agree with that statement? Surely text should be sufficient right, a url with 65k characters, does that even exist? Is there a disadvantage of not setting a max input length?

Nakov's avatar

I would put a limit, and I would also add the validation rule to check for the limit.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

URLs should never be more than 2048 characters.

 $table->string('googmaps',2048)->nullable();

The default is just 255

1 like
< GDB >'s avatar

@snapey Thank you for your input!

I've updated the best answer to yours, as it :

  • shows I was wrong with assumption string length is max. 255 (that was just default) (so no need to change type)
  • You gave a guidance in max length.

nb: you are very convincing when saying 'never more than 2048 chars'

Specific reason for this? Or just exp?

Thanks!!

Snapey's avatar

2048 was the limit IE could accept. Whilst other browsers support longer URI. providers have had to work within the IE restriction.

1 like
< GDB >'s avatar

Thank you for clarifying! Nice to know!

Please or to participate in this conversation.