[英]Integer nullable column in laravel
是否可以在laravel中使用整数列nullabale?
我有表格image
,我存储多个图像,并获得我的posts
products
website_banner
,我需要它们可以为空。 例如,如果我为我的产品上传多个图像而不是我的帖子列的错误没有默认值!
我的迁移:
Schema::create('images', function (Blueprint $table) {
$table->increments('id');
$table->string('image');
$table->integer('post_id')->unsigned();
$table->integer('product_id')->unsigned();
$table->integer('banner_id')->unsigned();
$table->timestamps();
});
Schema::table('images', function($table) {
$table->foreign('post_id')->references('id')->on('posts');
$table->foreign('product_id')->references('id')->on('products');
$table->foreign('banner_id')->references('id')->on('banners');
});
$表 - >整数( 'banner_id') - >可为空的() - >无符号();
是的,只需将->nullable()
到您的行:
$table->integer('website_banner')->unsigned()->nullable();
你必须使用可空的
$table->integer('column_name')->nullable()->unsigned();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.