使用Doctrine DBAL在Laravel迁移中更改列类型会导致错误

4

我使用的是Laravel 5.2、Php7、Apache和Windows。

我的迁移文件名为“2016_03_30_095234_alter_date_update_news_table.php”。

class AddSlugUpdateNewsTable extends Migration
{
    /**
     * Run the migrations.
     * php artisan make:migration add_slug_update_news_table
     * @return void
     */
    public function up()
    {
        Schema::table('news', function (Blueprint $table) {
            $table->date('slug')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('news', function (Blueprint $table) {
            $table->dateTime('slug')->change();
        });
    }
}

但是在运行迁移后,

$\> php artisan migrate

给我返回了这个错误

[RuntimeException] 更改“news”表的列需要Doctrine DBAL。请安装“doctrine / dbal”。

我该怎么办?

3个回答

6
根据 Laravel 文档,如果您使用 ->change() 函数,您必须先安装 doctrine/dbal。请在终端中输入 composer require doctrine/dbal。保留 html 标签。

5
警告:仅在您确定要丢失该列的所有值并可以在其中获得新值时才使用此方法。
但是,如果您想要保留它们,则这不是正确的解决方案。
/**
 * Run the migrations.
 * php artisan make:migration alter_date_update_news_table
 * @return void
 */
public function up()
{
    Schema::table('news', function (Blueprint $table) {
        $table->dropColumn('date');
    });
    Schema::table('news', function (Blueprint $table) {
        $table->date('date')->after('image');
    });        
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('news', function (Blueprint $table) {
        $table->dropColumn('date');
    });
    Schema::table('news', function (Blueprint $table) {
        $table->dateTime('date')->after('image');
    });  
}

4

似乎你缺少一个依赖项。

使用Composer安装它:

composer require doctrine/dbal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接