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

1. 运行环境

alibaba cloud

1). 当前使用的 Laravel 版本?

Laravel Framework 8.83.27

2). 当前使用的 php/php-fpm 版本?

PHP 版本:
PHP 7.4.28 (cli)

3). 当前系统

CentOS Linux release 8.2.2004 (Core)

4). 业务环境

开发环境

5). 相关软件版本

nginx version: nginx/1.18.0
mysql> select version();
+————+
| version() |
+————+
| 5.6.50-log |
+————+
//: <> (提供相关软件的版本,如 Nginx 、MySQL、MongoDB 等)

2. 问题描述?

php artisan migrate:fresh --seed

报错消息

 SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'migration' at row 1 (SQL: insert into `migrations` (`migration`, `batch`) values (2014_10_12_000000_create_users_table, 1))

查看表 migrations

mysql> desc migrations;
+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| migration | varchar(20)      | NO   |     | NULL    |                |
| batch     | int(11)          | NO   |     | NULL    |                |
+-----------+------------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

修改表 migrantionsmigration 字段

mysql> desc migrations;
+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| migration | text             | YES  |     | NULL    |                |
| batch     | int(11)          | NO   |     | NULL    |                |
+-----------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

再次执行 还是报原来的错 且 migrationsmigration 字段 变回原来的类型

php artisan migrate:fresh --seed 

 SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'migration' at row 1 (SQL: insert into `migrations` (`migration`, `batch`) values (2014_10_12_000000_create_users_table, 1))
 mysql> desc migrations;

+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| id        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| migration | varchar(20)      | NO   |     | NULL    |                |
| batch     | int(11)          | NO   |     | NULL    |                |
+-----------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

3. 您期望得到的结果?

在框架内那个地方可以更改 migrations 表 的 migration 的类型
同时 执行后 不会跳回 原来的 varchar 类型

4. 您实际得到的结果?

[root@iZwz91u64hvs1r58q5s9fjZ blog]# php artisan migrate:fresh --seed
Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table

   Illuminate\Database\QueryException 

  SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'migration' at row 1 (SQL: insert into `migrations` (`migration`, `batch`) values (2014_10_12_000000_create_users_table, 1))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708// If an exception occurs when attempting to run a query, we'll format the error
    709// message to include the bindings with SQL, which will make this exception a
    710// lot more helpful to the developer instead of just the database's errors.
    711catch (Exception $e) {712throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714);
    715}
    716}

      +38 vendor frames 
  39  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

文件 Illuminate\Database\Migrations\DatabaseMigrationRepository.php
调用方法 createRepository
可以在AppServiceProvider中boot方法中配置字符串的默认大小

schema::defaultStringLength(191);
1年前 评论
dana (楼主) 11个月前
讨论数量: 2

文件 Illuminate\Database\Migrations\DatabaseMigrationRepository.php
调用方法 createRepository
可以在AppServiceProvider中boot方法中配置字符串的默认大小

schema::defaultStringLength(191);
1年前 评论
dana (楼主) 11个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!