laravel迁移时将默认设置为NULL [英] Set default to NULL with laravel migration

查看:42
本文介绍了laravel迁移时将默认设置为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在迁移中的表中添加一个字段,希望允许它为NULL,但我也希望它默认为NULL.我应该在默认方法中放置什么?我担心放入"NULL" 会尝试放置一串 NULL ,而我显然不希望这样做.请帮忙:)

I am adding a field to a table in a migration that I wish to allow to be NULL but also I wish for it to default to NULL. What do I place in the default method? I fear that putting "NULL" in will attempt to place a string of NULLin which I obviously don't want. Please help :)

Schema::table('item_categories', function(Blueprint $table)
{
    $table->integer('parent_item_category_id')->unsigned()->nullable()->default($what_to_put here);
});

推荐答案

在字段上使用 nullable()方法时,该字段默认为NULL.

When you use the nullable() method on a field, that field will default to NULL.

这篇关于laravel迁移时将默认设置为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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