【问题标题】:Laravel 5.8 getting error when "char" type column migrationLaravel 5.8 在“char”类型列迁移时出错
【发布时间】:2020-05-13 06:52:07
【问题描述】:

我正在尝试在 laraval 5.8 中使用 php artisan migrate 命令更改我的 char 类型列默认值,但出现以下错误:

Unknown column type "char" 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.

我当前的脚本如下:

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddTypeDeafultValueProjectsTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{

    Schema::table('projects', function (Blueprint $table) {
        $table->char('type', 50)->nullable(true)->change();
    });



}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('projects', function (Blueprint $table) {
        //
    });
}
}

我没有遇到其他数据类型列的问题,但只有 char 出现上述错误。 请帮我解决这个问题?

【问题讨论】:

标签: php mysql laravel laravel-5


【解决方案1】:

您需要在迁移脚本中添加以下脚本:

添加以下或以上使用 Illuminate\Database\Migrations\Migration;

 use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\Type;

然后在 inside up 函数中添加以下脚本并再次尝试 php artisan migrate。

    if (!Type::hasType('char')) {
        Type::addType('char', StringType::class);
    }

【讨论】:

    猜你喜欢
    • 2015-07-28
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 2018-05-03
    • 1970-01-01
    • 2016-11-21
    • 2019-01-12
    相关资源
    最近更新 更多