首页 > 解决方案 > DB:SEED Laravel 6 不起作用

问题描述

这是我得到的错误。

chenasmartin@MacBook-Air-von-Chenas blog % php artisan db:seed

   Illuminate\Database\QueryException  : SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'description' at row 1 (SQL: insert into `companies` (`user_id`, `cname`, `slug`, `address`, `phone`, `website`, `logo`, `cover_photo`, `slogan`, `description`, `updated_at`, `created_at`) values (57, Ondricka-Mraz, ondricka-mraz, 4277 Helga Mount
Amandaview, OH 09189, 231-727-1719, parisian.net, avatar/man.jpg, cover/tumblr-image-sizes-banner.png, learn-earn and grow, Nesciunt eveniet quia iste. Architecto ipsa ad provident molestias rem nisi. Blanditiis tempora nostrum sequi error excepturi velit occaecati. Quis ab et ab reprehenderit. Facere quae et odio deserunt dolores vel autem provident. Eligendi eum dolore eos sunt dolorem. Vero est odio vel quia cum et. Velit quia et sed ipsa. Vero rerum iste laboriosam deserunt expedita similique et hic. Consequuntur enim assumenda repellat et inventore numquam. Ut saepe et beatae rerum facere. Ullam quia laudantium nisi. Autem sint sed eos fugit voluptatibus alias., 2021-03-25 12:32:59, 2021-03-25 12:32:59))

  at /Applications/XAMPP/xamppfiles/htdocs/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673| 

  Exception trace:

  1   PDOException::("SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'description' at row 1")
      /Applications/XAMPP/xamppfiles/htdocs/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:463

  2   PDOStatement::execute()
      /Applications/XAMPP/xamppfiles/htdocs/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:463

  Please use the argument -v to see more details.

https://github.com/chenas-sketch/Factory

这是我的 github 和我发布的代码。

标签: phplaravel

解决方案


您有一个companies带有字符串列的表,称为description字符串列,它不能容纳长文本,请将其从字符串更改为文本,以便它可以容纳这么多的数据。

因此,在您的 create_companies_table 迁移中:

 $table->text('description')->nullable(); // nullable or not it's your choice

推荐阅读