【问题标题】:laravel 5.2 migration add column/field before or after specific columnlaravel 5.2迁移在特定列之前或之后添加列/字段
【发布时间】:2016-09-09 02:09:23
【问题描述】:

例如,我知道如何将列/字段添加到数据库中

<?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()
    {
        //
    }


}

但它会附加到表的最后一个字段,但我想添加到特定列,例如在 created_at 之后插入字段,可以这样做吗?

【问题讨论】:

标签: php laravel-5.2


【解决方案1】:

如果您在 MySQL 上,可以使用 after 修饰符。

$table->integer('status')->after('created_at');

-&gt;after('column')将该列“放在”另一列“之后”(仅限 MySQL)

Laravel Docs - Migrations - Creating Columns - Column Modifiers

【讨论】:

  • 还有一个-&gt;first() 将其放在其他所有内容之前。不过没有-&gt;before()
猜你喜欢
  • 2020-03-08
  • 2014-01-25
  • 2015-10-20
  • 2018-05-01
  • 2018-06-28
  • 2020-04-10
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
相关资源
最近更新 更多