1

I have an error saving a field to the database, which is giving me the error: String data, right truncated: 1406 Data too long for column 'content' at row 1.

However the field in the database is set to Type: String, length 191. Which i believe translates to varchar.

Anybody else had this?

m33bo
  • 1,334
  • 1
  • 17
  • 34

3 Answers3

1

https://stackoverflow.com/a/13182846/2693543

copied from above answer

VARCHAR(X) Case: user name, email, country, subject, password

TEXT Case: messages, emails, comments, formatted text, html, code, images, links

MEDIUMTEXT Case: large json bodies, short to medium length books, csv strings

LONGTEXT Case: textbooks, programs, years of logs files, harry potter and the goblet of fire, scientific research logging

Shobi
  • 10,374
  • 6
  • 46
  • 82
1

Use this in your migration file and it will change your column data type and then you can save html content into it without any problem.

public function up()
{
    Schema::table('the_table_name', function () {
        $table->longText('columnName')->change();
    });
}

public function down()
{
    Schema::dropIfExists('the_table_name');
}
Zakir hussain
  • 621
  • 3
  • 12
0

You should NOT store a posts or pages content (something that contains a lot of text/html) as String.

Instead use TEXT for the MySQL column type, which allows to enter enough characters in there.

Ozan Kurt
  • 3,731
  • 4
  • 18
  • 32