简体   繁体   English

Laravel 4 Artisan从表中删除现有列

[英]Laravel 4 Artisan drop existing column from table

I created a migration script that creates a table called Archives. 我创建了一个迁移脚本,用于创建一个名为Archives的表。

It has 4 columns not including timestamps/increments. 它有4列不包括时间戳/增量。 The tables columns are name, title, content and image. 表格列是名称,标题,内容和图像。

I need to drop the image column as it is no longer needed. 我需要删除不再需要的图像列。

I have not been able to find a way to do this by searching and was hoping someone could give me the best way to do this. 我无法通过搜索找到一种方法来做到这一点,并希望有人能给我最好的方法来做到这一点。

I attempted to accomplish this by creating a new migration and then running 我尝试通过创建新的迁移然后运行来实现此目的

php artisan migrate:rollback --pretend php artisan migrate:rollback --pretend

But this tries to roll back the previous migration. 但这会尝试回滚先前的迁移。

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');
        });
    }
}

Almost there change drop_column to dropColumn 几乎将drop_column更改为dropColumn

Referenced Here http://laravel.com/docs/schema#renaming-columns 参考http://laravel.com/docs/schema#renaming-columns

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

Edit Referenced here for 5.1 http://laravel.com/docs/5.1/migrations 编辑此处参考5.1 http://laravel.com/docs/5.1/migrations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM