我有一个名为 "table_1" 的表格,它是通过多次迁移(添加/更改字段)来制定的。
我想要创建一个新的表格 "copy_of_table_1" (使用迁移),其结构与 "table_1" 相同。最好的方法是什么?
我希望避免创建新的迁移并复制粘贴所有添加和更改的字段。
我想要创建一个新的表格 "copy_of_table_1" (使用迁移),其结构与 "table_1" 相同。最好的方法是什么?
我希望避免创建新的迁移并复制粘贴所有添加和更改的字段。
您可以使用原始查询来完成这个操作:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class MyNewTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('CREATE TABLE newtable LIKE oldtable; ');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('newtable');
}
}
绝对不建议,但是可能实现。