Laravel 5中的回滚错误

时间:2018-02-17 01:12:54

标签: laravel laravel-5

我想删除一个列,但是对于“回滚”它总是显示错误!

  

错误:解析错误:语法错误,意外的文件结束,expectinf函数(T_FUNCTION)或const(T_CONST)

代码:

    <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class DropBody extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
          $table->dropColumn('body');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
           $table->mediumText('body');
        });
    }
}

1 个答案:

答案 0 :(得分:0)

我猜你正在编写反向代码,通过反向代码我的意思是说你必须在up函数中创建表字段并在down函数中删除列。

你应该尝试这样的事情:

/**
 * Run the migrations.
 *
 * @return void
 */
  public function up()
  {
      Schema::table('posts', function (Blueprint $table) {
            $table->mediumText('body');
       });
  }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('posts', function (Blueprint $table) {
          $table->dropColumn('body');
    });
}