Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQLSTATE[HY000]:一般错误:1364字段';联系人ID';不';没有默认值_Php_Mysql_Laravel_Eloquent - Fatal编程技术网

Php SQLSTATE[HY000]:一般错误:1364字段';联系人ID';不';没有默认值

Php SQLSTATE[HY000]:一般错误:1364字段';联系人ID';不';没有默认值,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,在我的型号(Customer)上,我有一个必需的参数:$contactId 执行Customer::create(['contactId'=>$contactId])时,我收到以下错误: “消息”:“SQLSTATE[HY000]:一般错误:1364字段“contactId”没有默认值(SQL:insert intocustomers(在更新,在创建)值(2019-12-10 12:33:462019-12-10 12:33:46))” insert语句中找不到contactId字段。conta

在我的型号(
Customer
)上,我有一个必需的参数:
$contactId

执行
Customer::create(['contactId'=>$contactId])
时,我收到以下错误:

“消息”:“SQLSTATE[HY000]:一般错误:1364字段“contactId”没有默认值(SQL:insert into
customers
更新,
创建)值(2019-12-10 12:33:462019-12-10 12:33:46))”

insert语句中找不到contactId字段。
contactId
的值设置为
4
,该值通过
FK
与数据库中的正确值相对应

客户
表的迁移:


`架构::创建('customers',函数(Blueprint$表){
$table->bigIncrements('id');
$table->timestamp('created_at')->默认值(DB::raw('CURRENT_timestamp');
$table->timestamp('updated_at')->默认值(DB::raw('CURRENT_timestamp on update CURRENT_timestamp');
$table->bigInteger('contactId')->unsigned();
$table->foreign('contactId','FK_customer\u contactId\u contact\u id'))
->引用('id')
->关于(“联系人”);
});`
是什么阻止了
雄辩的
在此处创建正确的insert语句?在整个流程和数据库中,我已经三次检查了
contactId
的拼写

当我在
客户
中手动插入一行时,检索数据和
联系人
-关系没有问题


谢谢你的时间

客户
型号中设置contactId
$filleble

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $fillable = ['contactId'];
}

如果使用
创建
方法将数据保存到数据库中,则必须在模型中写入此
可填充
属性

<?php

class Customer extends Model
{
    protected $fillable = ['contactId'];
}

使contactId$可在模型中填充

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $fillable = ['contactId'];
}

$contactId
一个空值吗?@JeremyHarris它不可为空。原来我没有完全理解$fillable的工作原理。迪利普:他的答案是正确的。
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $guarded = [];
}