[英]How can I create laravel migration with enum type column?
I am trying to create enum column in laravel migration.我正在尝试在 laravel 迁移中创建枚举列。 Upon executing the query it does create column in the table but checking in postgresql for created enum types, it shows theres none.
执行查询后,它确实在表中创建了列,但在 postgresql 中检查创建的枚举类型时,它显示没有。 Does anyone ever experience this?
有没有人经历过这个?
I am using laravel 5.4, php 7 and vagrant我正在使用 laravel 5.4、php 7 和 vagrant
Migration code迁移代码
public function up()
{
Schema::create('restaurant_tables', function(Blueprint $table){
$table->increments('_id');
$table->string('tableNo', 100);
$table->json('spatialLocation');
$table->enum('tableStatus' , array('Occupied', 'Reserved', 'Vacant', 'For Cleaning'))->default('Vacant');
$table->integer('numberOfCustomers');
$table->integer('seatLimit');
$table->string('tableDimension', 100);
$table->enum('tableType', ['4x4','16x4','8x4']);
$table->bigInteger('chairID');
});
Schema::table('restaurant_tables', function(Blueprint $table){
$table->foreign('chairID')->references('_id')->on('restaurant_chairs');
});
}
You can simply do:你可以简单地做:
$table -> enum('tableStatus',['VACANT','OCCUPIED','RESERVED','FOR CLEANING'])->default('VACANT');
$table->enum('tableStatus',['Vacant', 'Reserved', 'Occupied', 'For Cleaning']);
Try this尝试这个
Now Vacant is default value.现在空置是默认值。
$table->enum('tableStatus' , array('Vacant', 'Reserved', 'Vacant', 'For Cleaning'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.