当我尝试保存新属性时出现以下错误:
SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(STORMPATH_CLIENT_APIKEY_SECRET
。lightning
,CONSTRAINT residentials
FOREIGN KEY({{ 1}})参考residentials_residential_type_id_foreign
(residential_type_id
))(SQL:插入residential_types
(id
,residentials
,furnished
,{{1 }},rooms
,rent
)值(1,1,100,17,2016-07-06 23:32:59,2016-07-06 23:32:59))
我不明白为什么。
物业模型:
property_id
地址模型
updated_at
住宅模型:
created_at
residential_type模型
protected $table = 'properties';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id', 'is_for_sale','available','title', 'description','price'
];
public function user()
{
return $this->belongsTo('App\User');
}
public function Residential()
{
return $this->hasOne('App\Residential');
}
/**
* The Addresses that belong to the properties.
*/
public function addresses()
{
return $this->belongsToMany('App\Address');
}
我的控制器功能,我尝试保存属性以及相关住宅表中的字段,但我得到上面的错误。物业和地址保存正确,只是在住宅方面失败。
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'building_name', 'street_number', 'street_name', 'town', 'county', 'postcode','is_deleted'
];
/**
* The Users that belong to the Address.
*/
public function user()
{
return $this->belongsToMany('App\User');
}
/**
* The Users that belong to the Address.
*/
public function organisation()
{
return $this->belongsToMany('App\Organisation');
}
/**
* The Users that belong to the Address.
*/
public function Property()
{
return $this->belongsToMany('App\Properties');
}