重命名列名使用 laravel 迁移使用学说/dbal 给出错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29907605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:27:27  来源:igfitidea点击:

Rename column name using laravel migration using doctrine/dbal gives error

phplaraveldoctrine

提问by Amonra

Im trying to rename a database column in my localhost so that i can later do it in development and production

我试图重命名我的本地主机中的数据库列,以便我以后可以在开发和生产中进行

Im using laravel 5 and installed doctrine dbal.

我使用 Laravel 5 并安装了 Dotctic dbal。

Code of my migration:

我的迁移代码:

    $table->renameColumn('puesto', 'aux');

After I run php artisan migrateit tells me that

我运行后php artisan migrate它告诉我

[Doctrine\DBAL\DBALException]                                                                         
Unknown database type json requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it. 

The column im trying to rename isnt even json, although there are json column in the table, in fact only one called 'alianzas'. My question is, how can i rename the columns from the migration and not manually in the database.

我试图重命名的列甚至不是 json,尽管表中有 json 列,实际上只有一个名为 'alianzas' 的列。我的问题是,如何重命名迁移中的列而不是在数据库中手动重命名。

回答by surfer190

It looks like laravelonly suggests the install.

看起来laravel只建议安装。

You can install it with:

您可以使用以下命令安装它:

composer require doctrine/dbal

回答by Jesus Leon

Modifying Columns

修改列

Prerequisites

先决条件

Before modifying a column, be sure to add the doctrine/dbaldependency to your composer.jsonfile. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column.

在修改一个列之前,一定要在你的composer.json文件中添加doctrine/dbal依赖项。Doctrine DBAL 库用于确定列的当前状态并创建对列进行指定调整所需的 SQL 查询。

"require": {
    "doctrine/dbal": "^2.5"
},

composer require doctrine/dbal

Updating Column Attributes

更新列属性

The change method allows you to modify an existing column to a new type, or modify the column's attributes. For example, you may wish to increase the size of a string column. To see the change method in action, let's increase the size of the name column from 25 to 50:

change 方法允许您将现有列修改为新类型,或修改列的属性。例如,您可能希望增加字符串列的大小。要查看 change 方法的实际效果,让我们将 name 列的大小从 25 增加到 50:

Schema::table('users', function ($table) {
    $table->string('name', 50)->change();
});

回答by raphaelsaunier

This error still occurs in Laravel 5.1, even when doctrine/dbalis installed.

这个错误在 Laravel 5.1 中仍然出现,即使doctrine/dbal安装了。

As a temporary workaround, you could write your migration in raw SQL like so:

作为临时解决方法,您可以使用原始 SQL 编写迁移,如下所示:

public function up(){
  DB::statement("ALTER TABLE table_name RENAME puesto TO aux");
}