- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的模型 (Customer
) 上,我有一个必需参数:$contactId
。
在执行 Customer::create(['contactId' => $contactId])
时,我收到以下错误:
"message": "SQLSTATE[HY000]: General error: 1364 Field 'contactId' doesn't have a default value (SQL: insert into
customers
(updated_at
,created_at
) values (2019-12-10 12:33:46, 2019-12-10 12:33:46))"
在插入语句中找不到 contactId 字段。 contactId
的值设置为4
,它通过FK
对应到数据库中的正确值。
Customer
表的迁移:
`Schema::create('customers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
$table->bigInteger('contactId')->unsigned();
$table->foreign('contactId', 'FK_customer_contactId_contact_id')
->references('id')
->on('contacts');
});`
是什么阻止了 Eloquent
在此处创建正确的插入语句?我在整个流程和数据库中对 contactId
的拼写进行了三次检查。
当我手动向 customers
中插入一行时,检索数据和 contact
关系没有任何问题。
感谢您的宝贵时间!
最佳答案
在 Customer
模型中使 contactId $fillable
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $fillable = ['contactId'];
}
关于php - SQLSTATE[HY000] : General error: 1364 Field 'contactId' doesn't have a default value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59267758/
我有一个记录用户事件的表: AccountID/ContactID/Message/Time/Date 都被记录下来。通常消息将是一种颜色,红色,绿色等... 任何 AccountID 都可以有多个
我正在尝试以编程方式获取新添加联系人的 contactId。正在成功添加联系人并从 ContentProviderResult[] 获取 contactID 但我得到的 contactId 不正确。我
我正在尝试在 android 中创建一个具有特定联系人 ID 的 rawcontact,因此它链接到具有相同 contactid(不是 rawcontactid)的其他 rawcontact。 问题是
在我的模型 (Customer) 上,我有一个必需参数:$contactId。 在执行 Customer::create(['contactId' => $contactId]) 时,我收到以下错误:
以下函数将电话号码作为输入参数(例如 +436641234567 或 +436641234567)并在联系人数据库中执行两次查找:首先,识别属于该号码的用户(这已经有效),然后使用该 ID用户的 获取
我使用 EclipseLink 从 MySQL 生成我的所有对象,我有一个名为 CONTACT_ID 的字段。当我尝试 em.persist(contact) 时,我收到一条错误消息“Unknown
我是一名优秀的程序员,十分优秀!