Laravel迁移将列类型从varchar更改为longText

编程入门 行业动态 更新时间:2024-10-28 04:24:34
本文介绍了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

本文发布于:2023-10-17 22:05:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   Laravel   longText   varchar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!