Laravel迁移将列类型从varchar更改为longText [英] Laravel migrations change a column type from varchar to longText

查看:339
本文介绍了Laravel迁移将列类型从varchar更改为longText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将迁移列类型为$table->string('text');更改为文本类型,我尝试了几种方法来实现此目的,但是它们都没有起作用.是否可以在一次迁移中做到这一点.我想我可以删除该列,然后使用新类型再次创建它,但是我想知道是否可以在一次迁移中做到这一点?

I need to change with migration column type of $table->string('text'); to a text type, I have tried to do that in few ways, but none of them worked. Is it possible to do it in one migration. I could I guess drop the column and then create it again with new type, but I wonder if it is possible to do it in one migration?

推荐答案

您可以创建新的迁移,并

You can create a new migration and change just one column type:

public function up()
{
    Schema::table('sometable', function (Blueprint $table) {
        $table->text('text')->change();
    });
}

您需要安装doctrine/dbal才能使其正常工作

You need to install doctrine/dbal to make this work

composer require doctrine/dbal

可与Laravel 5.0及更高版本一起使用.它不适用于Laravel 4.2.

Works with Laravel 5.0+. It does not work with Laravel 4.2.

这篇关于Laravel迁移将列类型从varchar更改为longText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆