【问题标题】:Cannot drop column of existing table in Laravel 5.3?无法在 Laravel 5.3 中删除现有表的列?
【发布时间】:2017-03-31 03:38:49
【问题描述】:

我在 Laravel 5.3 中遇到问题。

它不允许我从现有表中删除列。我已经运行了“composer 需要学说/dbal”并且效果很好,但我的专栏不会删除。

我的 add_column_to_table 代码:

<?php

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

class AddColumnToTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table)
        {
            $table->string('avatar')->default('default.pngs');
        });
    }

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

谢谢

【问题讨论】:

  • 你看到了什么错误
  • 改用removeColumn()
  • 不确定这是否会有所不同,但我认为您在添加(或修改)列时通常不会使用Blueprint
  • @user2693928 -- 没有错误,该列没有删除

标签: php database laravel migration laravel-5.3


【解决方案1】:

要删除列,您需要按以下方式回滚迁移

php artisan migrate:rollback

【讨论】:

  • 啊,是的,我遇到的问题是我只是使用'php artisan migrate'
【解决方案2】:

试试这个:

public function down()
{
    Schema::table('users', function (Blueprint $table)
    {
        $table->dropColumn('avatar');
     });
    }
}

【讨论】:

    【解决方案3】:

    您应该回滚迁移:

    php artisan migrate:rollback
    

    但请确保您的桌子上的该列是空的。

    【讨论】:

      猜你喜欢
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 2017-06-07
      • 2017-02-27
      • 2018-06-04
      • 2017-02-19
      • 1970-01-01
      相关资源
      最近更新 更多