没有不值得去解决的问题,也没有不值得去学习的技术!

Fix “Unknown column type ‘tinyinteger’” Error When Modifying unsignedTinyInteger in Laravel 9 Migrations

In Laravel 9, when modifying a column type to unsignedTinyInteger in a database migration, an error occurs: Unknown column type "tinyinteger" requested.

1. In Laravel 9, when modifying a column type to unsignedTinyInteger in a database migration, an error occurs: Unknown column type “tinyinteger” requested. See Figure 1.

In Laravel 9, when modifying a column type to unsignedTinyInteger in a database migration, an error occurs: Unknown column type "tinyinteger" requested.
Figure 1
PHP

$table->unsignedTinyInteger('status')->default(1)->comment('状态,1:待处理;2:处理中;3:可换单;4:已完成')->change();

Plaintext

Unknown column type "tinyinteger" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.

2. Because Laravel’s Schema builder does not support the column type unsignedTinyInteger when updating column attributes, you need to use raw SQL statements.

PHP

use Illuminate\Support\Facades\DB;

DB::statement("ALTER TABLE return_orders MODIFY status tinyint unsigned NOT NULL DEFAULT 1 COMMENT '状态,1:待处理;2:处理中;3:可换单;4:已完成'");

3. Run the migration, and the update succeeds, as shown in Figure 2.

Run the migration, and the update succeeds
Figure 2
SQL

`status` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:待处理;2:处理中;3:可换单;4:已完成',

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系