在 Laravel 迁移中更改列会导致异常:更改表的列需要 Doctrine DBAL

问题描述 投票:0回答:4

我正在尝试在一次迁移中更改表

reserves
中一列的最大长度。代码如下所示:

public function up()
{
    //
    Schema::table('reserves', function($table){
        $table->string("mobile", 11)->change();
    });
}

但是当通过 artisan 运行迁移时,它会抛出异常并显示:

[RuntimeException] 更改表“reserves”的列需要 DBAL 学说;安装“doctrine/dbal”。

问题是什么以及如何解决?

laravel laravel-5 database-migration
4个回答
123
投票

在框架根目录执行以下命令解决了问题:

composer require doctrine/dbal

3
投票

添加到composer.json

"require": {
        ...
        "doctrine/dbal": "*"
    },

运行“composer update”命令


0
投票

或者如果您无法安装该库,则:

        DB::statement('ALTER TABLE `reserves` MODIFY mobile varchar(11)');

0
投票

更新列名的方法有很多种

选项1:通过composer安装

doctrine/dbal

composer require doctrine/dbal

注意:如果您不想安装软件包,请转到

option 2

选项 2: 使用

DB::statement
alter
查询来更新列

DB::statement('ALTER TABLE reserves MODIFY COLUMN mobile VARCHAR(11)');
  
© www.soinside.com 2019 - 2024. All rights reserved.