如何在laravel 5.6中更改列数据类型? [英] How to change column data type in laravel 5.6?
问题描述
我正在尝试使用laravel 5.6更改列数据类型.
I am trying to change column data type using laravel 5.6.
我有一个表,其中两列的数据类型为 text
,但我想将其更改为 longtext
.我尝试过以下操作:
I have a table in which two columns have a data type of text
but I would like to change it to longtext
. I have tried following:
- 执行过的
composer需要doctrine/dbal
- 执行了
composer dump-autoload
...然后为 log_requests
表创建了迁移 2019_12_23_065820_change_response_column_data_type_in_log_requests_table.php
.
...and then created the migration 2019_12_23_065820_change_response_column_data_type_in_log_requests_table.php
for log_requests
table.
...然后是以下脚本
...and then the following script
public function up()
{
Schema::table('log_requests', function (Blueprint $table) {
$table->longText('request')->nullable()->change();
$table->longText('response')->nullable()->change();
});
}
但是它并没有改变列的数据类型.有人可以指导我吗?我在哪里错了以便可以修复它?谢谢.
But it is not changing the column's data type. Can someone guide me? Where am I wrong so that I can fix it? Thank you.
已编辑
在注释中请求迁移后,我添加了迁移脚本:
After requesting for migration in comment, I added migration script:
public function up()
{
Schema::create('log_requests', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('user_id')->nullable()->unsigned();
$table->string('api_name')->nullable();
$table->string('url')->nullable();
$table->string('method')->nullable();
$table->string('ip_address')->nullable();
$table->string('status_code')->nullable();
$table->string('duration')->nullable();
$table->text('request')->nullable();
$table->text('response')->nullable();
$table->timestamps();
});
}
推荐答案
只需更改列注释,例如:
Just change the column comment, for example:
$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down
这篇关于如何在laravel 5.6中更改列数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!