Laravel 5.3 Schema::create ENUM field is VARCHAR

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-23 08:53:46

问题


I just created fresh migration. After running it I see my field type not ENUM type. It has a VARCHAR(255) type instead

Schema::create('payments', function (Blueprint $table) {
          $table->increments('id');
          $table->text('response');
          $table->enum('type', ['apple', 'paypal']);
          $table->smallInteger('flags');
          $table->timestamps();

        });

Can somebody tell me what can be the reason. Am I missing something, I tried multiple times - getting same result.

I'm using PostgreSQL 9.5.4


回答1:


From the Laravel source code

protected function typeEnum(Fluent $column)
{
    $allowed = array_map(function ($a) {
        return "'{$a}'";
    }, $column->allowed);
    return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed).'))';
}

It will create a varchar(255) column and will add a constraint so that it allows only the specified strings.



来源:https://stackoverflow.com/questions/40384827/laravel-5-3-schemacreate-enum-field-is-varchar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!