テーブルにレコードを挿入しようとすると、次のエラーが発生します。
エラー: SQLSTATE[23000]: 整合性制約違反: 1452 子行を追加または更新できません: 外部キー制約が失敗しました ( invoice
. quotes
, CONSTRAINT quotes_ibfk_1
FOREIGN KEY ( contacts_id
) REFERENCES Contacts
( id
))
「連絡先」と「見積もり」の 2 つのテーブルの間に関係を設定しています。「quotes」には、contacts_id を設定する外部キーがあります。
引用符コントローラーの Add メソッドは次のようになります。
public function add() {
$this->log('Quote Controller --> Add Method...1');
$this->log($this->request->data);
if ($this->request->is('post')) {
$this->Quote->create(); // This line writes the details to the database.
if ($this->Quote->save($this->request->data)) {
$this->Session->setFlash('Your quote has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your quote.');
}
}
}
どんな助けでも感謝します。