问题
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