简体   繁体   English

SQLSTATE [HY000]:常规错误:1364字段“ reservation_id”没有默认值

[英]SQLSTATE[HY000]: General error: 1364 Field 'reservation_id' doesn't have a default value

I can't get through in my code. 我无法通过我的代码。 I have error indicating that ' reservation_id ' doesn't have a default value. 我收到错误消息,表明“ Reservation_id ”没有默认值。 This reservation_id of table reservation_participate_details is a foreign key from the parent table reservation 's id column. reservation_participate_details的这reservation_id是从父表中保留的id列的外键。 I wonder if there is something to do with the hasMany or belongsTo thing. 我想知道hasManybelongsTo是否有关 I am not yet familiar deeply on laravel. 我还不太熟悉laravel。

The reservation table should/has many rows in the reservation_participate_details . 预约表应/已在reservation_participate_details多行。 The process is working before but when I changed a column (reservation_participate_id) of reservation_participate_details into reservation_id and point it as a foreign key of reservation 's column id , it is now not working. 这个过程之前的工作,但是当我改变reservation_participate_details的列(reservation_participate_id)到reservation_id并指出它作为保留id列的外键,它现在不工作。

I have tried to put 我试图把

    public function participateDetail()
    {
        return $this->hasMany('App\ReservationParticipateDetail');
    }

into the reservation (parent) table and 进入预留 (父)表并

    public function reservation()
    {
        return $this->belongsTo('\App\Reservation');
    }

into the reservation_participate_detail table Reservation_participate_detail表中

I just need to save participate details into reservation_participate_details . 我只需要将参与详细信息保存到Reservation_participate_details中 Again, reservation table has many reservation_participate_details . 再次, 保留表具有许多Reservation_participate_details

Since you have changed the names of foreign key columns (not followed laravel default convention), you need to define those column names in relationship functions. 由于您已更改了外键列的名称(未遵循laravel默认约定),因此需要在关系函数中定义这些列的名称。

reservation model 预订模式

public function participateDetail()
{
    return $this->hasMany('App\ReservationParticipateDetail', 'reservation_id', 'id');
}

reservation participate details model 预订参与细节模型

public function reservation()
{
    return $this->belongsTo('\App\Reservation', 'reservation_id', 'id');
}

暂无
暂无

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

相关问题 SQLSTATE [HY000]:一般错误:1364 字段“agent_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'agent_id' doesn't have a default value SQLSTATE[HY000]:一般错误:1364 字段“parent_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'parent_id' doesn't have a default value Laravel Voyager SQLSTATE [HY000]:常规错误:1364字段“ id”没有默认值 - Laravel Voyager SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value SQLSTATE[HY000]:一般错误:1364 字段“client_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'client_id' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段'author_id'没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'author_id' doesn't have a default value Laravel SQLSTATE [HY000]:常规错误:1364字段“ id”没有默认值 - Laravel SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段“ mov_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'mov_id' doesn't have a default value SQLSTATE[HY000]:一般错误:1364 字段“country_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'country_id' doesn't have a default value SQLSTATE [HY000]:一般错误:1364 字段“trans_id”没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'trans_id' doesn't have a default value SQLSTATE [HY000]:常规错误:1364字段“照片”在laravel 5.5中没有默认值 - SQLSTATE[HY000]: General error: 1364 Field 'photo' doesn't have a default value in laravel 5.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM