我需要从我的数据库表clients中删除列UserDomainName.

起初,我通过执行composer require doctrine/dbalcomposer update来安装doctrine/dbal,如documentation中所述.

然后我创建了迁移,我想用它删除列:

php artisan make:migration remove_user_domain_name_from_clients --table=clients

我在down()方法中添加了Schema::dropColumn('UserDomainName');:

<?php

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

class RemoveDomainName extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('clients', function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('clients', function (Blueprint $table) {
            Schema::dropColumn('UserDomainName');
        });
    }
}

然而,我明白了

Migrating: 2017_08_22_135145_remove_user_domain_name_from_clients
Migrated:  2017_08_22_135145_remove_user_domain_name_from_clients

after executing php artisan migrate but no Column is dropped. If I execute it again I get Nothing to migrate.

推荐答案

down函数用于回滚,您必须将此dropColumn添加到up函数中,因为这是您在运行迁移时要执行的操作.

So, in your up function there should be:

Schema::table('clients', function (Blueprint $table) {
    $table->dropColumn('UserDomainName');
});

down函数中,您应该反其道而行之,将列添加回来:

Schema::table('clients', function (Blueprint $table) {
    $table->string('UserDomainName');
});

This way, you can always return to any point in the migrations.

Laravel相关问答推荐

如何定制有关密码被泄露的Laravel Breeze S消息?

在Laravel Sail Docker环境中的PHPMyAdmin中出现`Out of Memory‘错误

Laravel 通过 API 嵌套 url 发布

如何自定义密码确认不匹配.错误信息?

不能在 laravel 中使用控制器名称,必须使用命名空间

为什么 Laravel 5 会自动更新我的日期字段?

我在哪里放置事件侦听器和处理程序?

使用 Eloquent 的 Laravel 块方法

如何监控 Laravel 队列是否正在运行?

Laravel - 排序的集合输出不是数组

artisan 迁移错误找不到类'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver'

laravel 5 - assets资源 list 中未定义 css 文件?

SQLSTATE [01000]:警告:1265 列的数据被截断(truncated)

Laravel 5.1 重命名项目

Laravel - 批量分配异常错误

如何在 Laravel Eloquent 中 Select 某些字段?

Laravel 5:在同一字符串上使用 bcrypt 给出不同的值

测试指向外部站点的重定向链接

如何运行artisan命令计划:在托管服务器上运行? (Laravel )

laravel 如何读取 app/config/app.php 调试变量