繁体   English   中英

在迁移期间使列默认值在laravel 5.5中不起作用

[英]make column default value during migration not working in laravel 5.5

我正在尝试在迁移过程中将“ is_img”列的默认值设置为“ 0”。 当我尝试像- $table->integer('is_img')->defalut(0)->change(); 它将在迁移过程中删除现有列。 当尝试不使用change()方法时,则在迁移过程中会给出空值。 在迁移过程中应如何保留列的默认值? 这是模式波纹管-

public function up()
{
    Schema::create('admins', function (Blueprint $table) {
        $table->increments('id');
        $table->string('email');
        $table->string('user_name');
        $table->string('password');
        $table->string('login_type');
        $table->integer('is_img')->defalut(0)->change();
        $table->timestamps();
    });
}

您在此行中有错别字:

$table->integer('is_img')->defalut(0)->change();

应该是default(0)而不是defalut(0)

'defalut'是错别字,应该是'default', $table->integer('is_img')->default(0); 工作正常。 感谢@Esteban Garcia和@Hiren Gohel节省了我的时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM