问题描述:
Doctrine\DBAL\Exception
Unknown column type "enum" 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 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 ' .
刚开始好像还有doctrine/dbal版本过高的问题(2+升到3,有时候大版本升级不兼容),后面安装的版本是2.1.7就剩下面这个报错了。
Doctrine\DBAL\Exception
Unknown column type “enum” requested.
大概意思就是不支持修改,网上折腾了一圈最后是执行原生sql的方法解决的。
更新脚本
public function up()
{
Schema::table('script', function (Blueprint $table) {
$table->enum('type', ['python','shell','python3'])->change();
});
}
解决方案:
执行原生sql
可以参考一下博客园 https://www.cnblogs.com/songlen/p/13305306.html
当用 Laravel 的数据迁移来更新 Enum 类型的字段时,比如:修改字段名
Schema::table('table_name', function (Blueprint $table) {
$table->renameColumn('from', 'to');
});
当执行迁移命令的时候:
php artisan migrate
会报异常:
Doctrine\DBAL\DBALException:Unknown database type enum requested,
Doctrine\DBAL\Platforms\MySQL57Platform may not support it.
当遇到这个问题的时候,首先确保已经安装了扩展 doctrine/dbal ,因为 Laravel 官方文档已经提到:
在修改字段之前,请确保将 doctrine/dbal 依赖添加到 composer.json 文件中。Doctrine DBAL 库用于确定字段的当前状态, 并创建对该字段进行指定调整所需的 SQL 查询
如果没有安装此扩展,请执行命令安装:
composer require doctrine/dbal
然后修改迁移文件
DB::getDoctrineSchemaManager()
->getDatabasePlatform()
->registerDoctrineTypeMapping('enum', 'string');
Schema::table('pattern_column_orders', function (Blueprint $table) {
$table->renameColumn('payment', 'payment_method');
});
这时候再执行迁移命令发现已经可以成功执行了