I'm trying to add an enum option to a table (without losing the current dataset) using the schema builder.
The only thing I've really been able to find about column alteration is http://www.flipflops.org/2013/05/25/modify-an-existing-database-column-in-a-laravel-migration/ and I believe that was written for Laravel3.
尽管如此,我还是try 使用DB::query('ALTER TABLE…');命令,但它与call_user_func_array()一起出错.该命令要求参数1是有效的回调,类'illumb\Database\MySqlConnection'没有方法'query'.
DB::query("ALTER TABLE users CHANGE COLUMN permissions permissions ENUM('admin', 'user', 'candidate')");
我也试过这样做:
Schema::table('users', function ($table) {
$table->enum('permissions', array('admin', 'user', 'candidate'))->default('user');
});
but it errors out saying the column already exists.
在不丢失该列中的所有数据的情况下完成我正在try 的操作的最佳方式是什么?