有没有很好的方法可以做到这一点?目前,我是按照与我想要的顺序相反的顺序列出列的:
Schema::table('some_table', function($table){
$table->string('new_col_2')->after('existing_col'); //How to specify that this should come after new_col_1?
$table->string('new_col_1')->after('existing_col');
});
答案 0 :(得分:4)
如果存在existing_col
,我认为可以按“正常”顺序调用您创建的下一列:
Schema::table('some_table', function($table){
$table->string('new_col_1')->after('existing_col');
$table->string('new_col_2')->after('new_col_1');
});
答案 1 :(得分:2)
您尝试过吗:
Schema::table('some_table', function($table){
$table->string('new_col_1')->after('existing_col');
$table->string('new_col_2')->after('new_col_1');
}
答案 2 :(得分:2)
另一个更好的选择是
Schema::table('some_table', function($table){
$table->after('existing_col', function ($table) {
$table->string('new_col_1');
$table->string('new_col_2');
});
});