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

后端 未结 6 1571
予麋鹿
予麋鹿 2021-02-04 01:18

I have a table with a column \'hotel\'. The project is created in Laravel 5.4, so I used Migrations.

    $table->string(\'hotel\', 50);

Thi

相关标签:
6条回答
  • 2021-02-04 01:40

    Change column's datatype from string to text and do not give length.

    $table->text('hotel')->change();
    
    0 讨论(0)
  • 2021-02-04 01:43

    change the type of column fromstring to text.

    Then run a migrate refresh using php artisan migrate:refesh

    0 讨论(0)
  • 2021-02-04 01:45

    On your local development, try changing the column type to:

    $table->longText('columnName')
    

    from your migration file. That solved it for me. But if you have gone live, then create a new migration just as Alexey has suggested and then use longText() column type.

    0 讨论(0)
  • 2021-02-04 01:55

    I was storing pictures as base64 on a text colum so I got a SQL error:

    SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'picture' at row 1 
    

    I did my migration as

    $table->text('picture')
    

    then I changed de column picture as:

    $table->mediumText('picture')
    

    I realiced that text column allows to store only 64 KB

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

    For more info visit: understanding-strorage-sizes-for-mysql-text-data-types

    0 讨论(0)
  • 2021-02-04 01:58

    You need to create a new migration, register it with composer du command and run php artisan migrate command to change type of the column:

    Schema::table('the_table_name', function (Blueprint $table) {
        $table->string('hotel', 255)->change();
    });
    
    0 讨论(0)
  • 2021-02-04 02:02

    Change column's datatype from string to text and do not give length.

    0 讨论(0)
提交回复
热议问题