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)
修改表 migrantions
的 migration
字段
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)
再次执行 还是报原来的错 且 migrations
的 migration
字段 变回原来的类型
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.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+38 vendor frames
39 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
文件
Illuminate\Database\Migrations\DatabaseMigrationRepository.php
调用方法
createRepository
可以在AppServiceProvider中boot方法中配置字符串的默认大小