2 回答
TA贡献1998条经验 获得超6个赞
将您的新表向上迁移方法更改为:
public function up()
{
//Create the table
Schema::create('your_table_name', function (Blueprint $table) {
$table->bigIncrements('id')->unique();
$table->bigInteger('client_log_id');
$table->mediumText('partition_data');
$table->timestamps();
});
//Copy column from last table to new table
foreach(MyOldModel::all() as $item)
{
//now you can save old data into new table old data : $item -> log_data
//other operation you want
MyNewModel::create(array('partition_data' => $item -> log_data));//you can save other columns with adding array values
}
//Drop old table column
Schema::table('client_logs', function (Blueprint $table) {
$table->dropColumn('log_data');
});
}
我认为以这种方式也migrate:rollback命令应该可以工作(用于撤消您的更改)!
- 2 回答
- 0 关注
- 181 浏览
添加回答
举报