我有一个由多次迁移(添加/更改字段)制定的表"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');
}
}
绝对不推荐,但可能。
最好的方法是创建新的迁移并从所有添加/更改迁移中添加字段。我看不到任何更聪明的解决方案。