[英]laravel 5.2 migration add column/field before or after specific column
i know how to add column/field to to database for example 我知道如何将列/字段添加到数据库中
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddStatusToPhoto extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photos', function(Blueprint $table)
{
$table->integer('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
but it will append to the last field of the table, but i want to add to specific column eg insert the field after created_at, is it possible to do that? 但它会附加到表的最后一个字段,但我想添加到特定列,例如在created_at之后插入字段,是否可以这样做?
There is a after
modifier you can use if you are on MySQL. 如果您使用MySQL,则可以使用
after
修饰符。
$table->integer('status')->after('created_at');
->after('column')
Place the column "after" another column (MySQL Only)->after('column')
将列放在“另一列”后面(仅限MySQL)
Laravel Docs - Migrations - Creating Columns - Column Modifiers Laravel Docs - 迁移 - 创建列 - 列修改器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.