[英]Cannot drop column of existing table in Laravel 5.3?
I am having a problem in Laravel 5.3. 我在Laravel 5.3中遇到问题。
It won't allow me to drop a column from an existing table. 它不允许我从现有表中删除列。 I have run 'composer require doctrine/dbal' and that worked fine, but my column will not delete.
我已经运行了“ composer require doctrine / dbal”,并且效果很好,但是我的列不会删除。
My add_column_to_table code: 我的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');
});
}
}
Thanks 谢谢
要删除该列,您需要按以下方式回滚迁移
php artisan migrate:rollback
Try this: 尝试这个:
public function down()
{
Schema::table('users', function (Blueprint $table)
{
$table->dropColumn('avatar');
});
}
}
You should rollback your migration: 您应该回滚迁移:
php artisan migrate:rollback
But make sure that column is empty on your table. 但是,请确保该表在表中为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.