메신저 테이블에 데이터를 삽입하려고하는데 메신저에 2 개의 외래 키가 있고 메신저에서이 오류가 발생했습니다. 무엇이 잘못하고 있는지 전혀 모른다.SQLSTATE [23000] : 무결성 제약 조건 위반 : 1452 자식 행을 추가하거나 업데이트 할 수 없습니다. 외래 키 제약 조건이 실패했습니다. laravel 5.2
이것은 내 주식 모델입니다.
//voorraad = stock
// Model Voorraad has the attributes, Aantal and Id;
// foreign keys are Producten_Id and Locaties_Id from the table Producten and locaties table
class Voorraad extends Model
{
public $fillable = ['Id', 'aantal', 'Producten_Id', 'Locaties_Id'];
protected $table = 'Voorraad';
public $timestamps = false;
public function producten()
{
return $this->BelongsTo('App\Producten', 'Producten_Id');
}
public function locatie()
{
return $this->BelongsTo('App\Locatie', 'Locaties_Id');
}
}
이들은 데이터를 만들고 데이터베이스에 저장하는 데 사용하는 컨트롤러 기능입니다.
public function create()
{
//retuning the view with database tables producten and locaties passing through to the create view the Id
return view('voorraad.create',[
'producten' => Producten::all('Id'),
'locaties' => Locatie::all('Id')
]);
}
public function store(Request $request)
{
//Producten_Id is the foreign key from the table producten
//Locaties_Id is the foreign key form the table Locaties
//aantal is the ammout of a sertain product
Voorraad::create($request->only(['aantal', 'Producten_Id', 'Locaties_Id']));
return redirect(Route('voorraad.index'));
}
이 뷰
{!! Form::open(['url'=>'voorraad']) !!}
{!! Form::label('aantal', 'aantal:') !!}
{!! Form::text('aantal')!!} </br>
<div class="form-group">
{{ Form::label('producten_id', 'Producten_Id:') }}
{{ Form::Select('Producten_Id' , $producten, null) }}</br>
</div>
<div class="form-group">
{{ Form::label('Locatie_Id', 'Id:') }}
{{ Form::select('Locaties_Id', $locaties, null) }}
</div>
<div>
{!! Form::Submit('create', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
를 생성한다 {! Form :: close() !!}
누군가 내가 잘못하고있는 것을 말해 줄 수 있다면 크게 감사하겠습니다. 내가 포함시키는 것을 잊어 버린 것이 있다면 알려주세요. 질문에 추가하겠습니다.