【发布时间】:2019-07-15 08:15:42
【问题描述】:
我有一个 MySQL 数据库,其中包含一个名为 user_level_attempt 的表。该表有一个 ENUM 类型的列,其中包含 ['PROGRESSED', 'STOPPED', 'COMPLETED'] 值。我需要编写迁移以向该列添加另一个值(比如说“通过”)。添加后,它看起来像这样,['PROGRESSED', 'STOPPED', 'COMPLETED', 'PASSED]。我怎么能在 Laravel 中做到这一点? 我尝试了以下解决方案,但它似乎不是一个好的做法/解决方案。
/**
* Schema table name to migrate
* @var string
*/
public $set_schema_table = 'bt_user_level_attempt';
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table($this->set_schema_table, function ($table) {
$table->dropColumn('status');
});
Schema::table($this->set_schema_table, function ($table) {
$table->enum('status', ['PROGRESS', 'STOPPED', 'COMPLETED', 'PASSED'])->default('PROGRESS')->after('effective_time_spend');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table($this->set_schema_table, function ($table) {
$table->dropColumn('status');
});
Schema::table($this->set_schema_table, function ($table) {
$table->enum('status', ['PROGRESS', 'STOPPED', 'COMPLETED'])->default('PROGRESS')->after('effective_time_spend');
});
}
谢谢。
【问题讨论】:
标签: php laravel enums eloquent database-migration