【问题标题】:Laravel migration uknown database enum requested请求 Laravel 迁移未知数据库枚举
【发布时间】:2020-01-14 03:35:51
【问题描述】:

实时应用程序有订单表。

    Schema::create('order', function($table){

        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->dateTime('date')->nullable();

        $table->enum('status', array('CREATED','FINISHED'))->default('CREATED');
    });

现在我需要更新该表中的状态字段,但我想将旧数据保存在数据库中。所以我又创建了一个迁移,它将更新订单表中的状态字段。

    Schema::table('order', function($table){
        $table->enum('status', array('CREATED','FINISHED','CLOSED'))->default('CREATED')->change();
    });

但是当我运行php artisan migrate 时,我收到错误消息Unknow database type enum requested, Doctrine\DBal\Platforms\MySqlPlatform may not support it.

【问题讨论】:

  • 来自documentation: "只有以下列类型可以“更改”:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText 、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger 和 unsignedSmallInteger。” 以及“当前不支持重命名表中也有 enum 类型的列的任何列。

标签: php laravel laravel-migrations


【解决方案1】:

我建议你使用查询构建器的外观来实现相同的,

DB::statement("ALTER TABLE order CHANGE COLUMN status status  
ENUM('CREATED', 'FINISHED', 'CLOSED') NOT NULL DEFAULT 'CREATED'");

通过原始迁移是不可能的,

注意:- 只有以下列类型可以“更改”:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、 整数,json,longText,mediumText,smallInteger,字符串,文本,时间, unsignedBigInteger、unsignedInteger 和 unsignedSmallInteger。

【讨论】:

    猜你喜欢
    • 2015-05-23
    • 2016-01-13
    • 2017-01-26
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2019-11-18
    相关资源
    最近更新 更多