Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP saveMany meets foreign key constrain failed error?
    primarykey
    data
    text
    <p>I try to $this->MembersQuestionsAnswer->saveMany($data). </p> <p>And $data is this:</p> <pre><code>array( (int) 0 =&gt; array( 'member_id' =&gt; '4', 'questions_anwser_id' =&gt; '102' ), (int) 1 =&gt; array( 'member_id' =&gt; '4', 'questions_anwser_id' =&gt; '203' ) ) </code></pre> <p>then I got error</p> <blockquote> <p>Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>dating_sys</code>.<code>members_questions_answers</code>, CONSTRAINT <code>members_questions_answers_ibfk_2</code> FOREIGN KEY (<code>questions_answer_id</code>) REFERENCES <code>questions_answers</code> (<code>id</code>))</p> <p>SQL Query: INSERT INTO <code>dating_sys</code>.<code>members_questions_answers</code> (<code>member_id</code>, <code>modified</code>) VALUES (4, '2012-11-14 01:13:27')</p> </blockquote> <p>I checked the database. Both 102 and 203 do exist in table questions_answers id field. And I can also manually insert them into the table. Foreign key constraints work as I checked as well. </p> <p>And the table members_questions_answers table DDL is </p> <pre><code>CREATE TABLE `members_questions_answers` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL, `questions_answer_id` int(10) unsigned NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`), KEY `member_fk` (`member_id`) USING BTREE, KEY `questions_answer_fk` (`questions_answer_id`) USING BTREE, CONSTRAINT `members_questions_answers_ibfk_2` FOREIGN KEY (`questions_answer_id`) REFERENCES `questions_answers` (`id`), CONSTRAINT `members_questions_answers_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `members` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; </code></pre> <p>It feels like questions_answers table not really identified for some reason. I did have changed the name of this table and its foreign keys references. Is there a cache or something?</p> <p>Can anyone help or point me to a new way to look into?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload