最佳答案
我有一个博客的 articles
表 Schema
是这样定义的:
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->string('thumb')->nullable();
$table->text('excerpt');
$table->text('body');
$table->string('slug')->unique();
$table->integer('comment_count')->unsigned()->default(0);
$table->integer('view_count')->unsigned()->default(0);
$table->timestamps();
$table->softDeletes();
}
public function down()
{
Schema::drop('articles');
}
我希望在不丢失表中现有数据的情况下删除列 comment_count
和 view_count
我定义了这样一个新的迁移:
class RemoveCommentViewCount extends Migration
{
public function up()
{
//nothing here
}
public function down()
{
Schema::table('articles', function($table) {
$table->dropColumn('comment_count');
$table->dropColumn('view_count');
});
}
}
我做了 php artisan migrate
。它确实成功地迁移了,但是没有删除这两个列。
我做错了什么? 如何删除这些列而不丢失表中的现有数据?