在Laravel迁移中使列不可为空 [英] Make column not nullable in a Laravel migration
本文介绍了在Laravel迁移中使列不可为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个迁移,以使表nullable
中的某些列现在正确.对于down函数,我当然想再次使这些列成为not nullable
.我浏览了架构生成器文档,但找不到实现此目的的方法.
I'm writing a migration to make certain columns in a table nullable
right now. For the down function, I of course want to make those columns not nullable
again. I looked through the schema builder docs, but couldn't see a way to do this.
任何帮助将不胜感激.
推荐答案
在Laravel 5之前,还没有使用架构生成器来更改现有表列的Laravel本机方式.您需要为此使用原始查询.
Prior to Laravel 5 there was no Laravel native way of altering an existing table column using the schema builder. You'd need to use raw queries for this.
但是,从Laravel 5开始,您可以使用:
However, as of Laravel 5 you can use:
$table->...->nullable(false)->change();
这篇关于在Laravel迁移中使列不可为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文