我尝试为状态设置布尔值,但是我发现“状态”列不能为空。我该怎么办?下面是我为创建用户表设置的代码。
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('role')->nullable();
$table->boolean('status');
$table->string('address')->nullable();
$table->string('city')->nullable();
$table->string('postal_code')->nullable();
$table->string('phone')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
答案 0 :(得分:1)
为您的status
列设置默认值
$table->boolean('status')->default(0);
答案 1 :(得分:1)
$table->boolean('status')->nullable($value = true);
(默认情况下)允许将NULL值插入列
答案 2 :(得分:0)