Modify the type of the field in Laravel 6’s database migration
1. Now the field Theme_Asset of the table Theme_Asset is of type VARCHAR(255). The previous migration code is as follows. as shown in Figure 1
$table->string('theme_id')->nullable(false)->comment('主题Id');
2. Now plan to add a new migration file to modify the type of the field Theme_id is: UUID, that is, char(36).
$table->uuid('theme_id')->change();
3. Error: Doctrine\DBAL\Exception : Unknown column type “UUID” requested. As shown in Figure 2
PS E:\wwwroot\object> php artisan module:migrate ThemeStoreDB
Migrating: 2022_05_20_160818_update_theme_asset_table
Doctrine\DBAL\Exception : Unknown column type "uuid" 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.
at E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php:282
278| * @return Exception
279| */
280| public static function unknownColumnType($name)
281| {
> 282| return new Exception('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' .
283| 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
284| 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
285| 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
286| 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
Exception trace:
1 Doctrine\DBAL\DBALException::unknownColumnType("uuid")
E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\TypeRegistry.php:37
2 Doctrine\DBAL\Types\TypeRegistry::get("uuid")
E:\wwwroot\object\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\Type.php:237
Please use the argument -v to see more details.
4. After adjusting to char, the error is still reported: unknown column type “char” requested.
$table->char('theme_id', 36)->change();
5. The final decision to use db::statement, the code is as follows
DB::statement('ALTER TABLE ' . DB::connection()->getTablePrefix() . 'theme_asset MODIFY theme_id char(36) NOT NULL COMMENT \'文件内容\'');
6. View the SQL comparison of the generated table, which is in line with expectations. as shown in Figure 3
`theme_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主题Id',
`theme_id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主题Id',


