Laravel 5.8 在“char”类型列迁移时出错

你的观点是混乱的。首先添加表单操作然后添加按钮表单属性,如下所示:


<button type="submit" form="upload" class="btn btn-info pull-right" id="submit" data-loading-text='SOME TEXT'> Please wait<?php echo $this->lang->line('save'); ?></button>



<form id="upload" role="form" method="post" class="ptt10" enctype="multipart/form-data" action="upload_docs">

分享

703507  

703507  

703507  


我试图在 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数据库拉维laravel-5


倚天杖
浏览 89回答 1
1回答

白衣染霜花

您需要在迁移脚本中添加以下脚本:在 use Illuminate\Database\Migrations\Migration 下或之上添加以下内容;&nbsp;use&nbsp;Doctrine\DBAL\Types\StringType;&nbsp;use&nbsp;Doctrine\DBAL\Types\Type;之后在 inside up 函数中添加以下脚本并再次尝试 php artisan migrate。&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!Type::hasType('char'))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type::addType('char',&nbsp;StringType::class); &nbsp;&nbsp;&nbsp;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP