2

我剛剛創建了新的遷移。運行後,我看到我的字段type不是ENUM類型。它有一個VARCHAR(255)類型,而不是Laravel 5.3 Schema :: create ENUM字段是VARCHAR

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

     }); 

有人可以告訴我什麼都可以的原因。我錯過了什麼,我多次嘗試 - 獲得相同的結果。

我使用PostgreSQL 9.5.4

回答

4

從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).'))'; 
} 

這將創建一個varchar(255)列,使其只允許指定的字符串將添加一個約束。

+0

如何用DB :: statement()修改? – envision