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

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

Coding & Programming

I was working on a project today when i ran into the error message “String data, right truncated: 1406 Data too long for column ‘name’ at row 1” which appeared to be originating from my database. After resolving the issue i decided to drop a guide on how anyone can resolve similar issue if encountered in future.

If you are encountering such error, then it means the value being entered is as the error says “too long for the column”. On your local development, try changing the column type to:

$table->longText('columnName')

But if you have gone live, then create a new migration and then use longText() column type.
$table->text(‘columnName’) should be enough for most of the cases but since you might be dealing with a larger text character number, then $table->longText(‘columnName’) should be your fall back.

Here is a more simpler approach if you have already gone live;

  • Login into your server’s phpMyAdmin for the database.
  • Navigate to the table that is the source of the error message.
  • Once you have located the table, click on it. For clarity, i am making use of a test table i created.
  • Next in the table page, locate and click on Structure just as illustrated in the image below.
String data, right truncated
  • Locate the column name which was probably specified in the error message you received and click on the Change label.
  • Click on the drop down button for Type and scroll down to select the LONGTEXT string type.
  • Finally click on Save and you are done.

This is what resolved the error i was getting. I hope you find this helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *