我试图在laravel迁移中创建枚举列。在执行查询时,它确实在表中创建了列,但是在postgresql中检查创建的枚举类型,它显示没有。有人经历过吗?
我用的是laravel 5.4,php 7和vagrant
迁移代码
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');
});
}
3条答案
按热度按时间z8dt9xmd1#
您可以简单地执行以下操作:
umuewwlo2#
第一个默认
2izufjch3#
以下是解释:https://hbgl.dev/add-columns-with-custom-types-in-laravel-migrations/
希望这将为那些像我一样遇到这个问题的人节省保存一些时间。
简而言之:
替代版本(用于现有表格更新):
扩展Doctrine DBAL的其他步骤(例如,重命名时需要):
1.创建类
TableTypeEnumDbType
:1.把它添加到
config/database.php
: