【问题标题】:Laravel 4 Artisan drop existing column from tableLaravel 4 Artisan 从表中删除现有列
【发布时间】:2014-06-03 15:37:23
【问题描述】:

我创建了一个迁移脚本,它创建了一个名为 Archives 的表。

它有 4 列,不包括时间戳/增量。 表格列是名称、标题、内容和图像。

我需要删除不再需要的图像列。

我无法通过搜索找到执行此操作的方法,希望有人能给我最好的方法。

我试图通过创建一个新的迁移然后运行来实现这一点

php artisan migrate:rollback --pretend

但这会尝试回滚之前的迁移。

class DropImageColumnArchive extends Migration
{

    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::table('archives', function ($table) {
            $table->text('image');
        });
    }

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

【问题讨论】:

    标签: php laravel-4


    【解决方案1】:

    差点把drop_column改成dropColumn

    此处引用http://laravel.com/docs/schema#renaming-columns

    Schema::table('users', function($table)
    {
        $table->dropColumn('votes');
    });
    

    编辑此处引用 5.1 http://laravel.com/docs/5.1/migrations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2017-03-31
      • 2020-02-02
      • 1970-01-01
      • 2020-04-17
      • 2013-03-13
      • 2020-11-12
      相关资源
      最近更新 更多