phplaravelpostgresqleloquentlaravel-schema-builder

Laravel 5.3 Schema::create ENUM field is VARCHAR


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 and Laravel 5.3.


Solution

  • 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.