0

我尝试 $this->MembersQuestionsAnswer->saveMany($data)。

$data 是这样的:

array(
    (int) 0 => array(
        'member_id' => '4',
        'questions_anwser_id' => '102'
    ),
    (int) 1 => array(
        'member_id' => '4',
        'questions_anwser_id' => '203'
    )
)

然后我得到了错误

错误:SQLSTATE [23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(dating_sys. members_questions_answers, CONSTRAINT members_questions_answers_ibfk_2FOREIGN KEY ( questions_answer_id) REFERENCES questions_answers( id))

SQL 查询: INSERT INTO dating_sysmembers_questions_answers ( member_id, modified) 值 (4, '2012-11-14 01:13:27')

我检查了数据库。表 questions_answers id 字段中确实存在 102 和 203。而且我也可以手动将它们插入表格中。正如我检查的那样,外键约束也有效。

并且表 members_questions_answers 表 DDL 是

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 ;

感觉就像 questions_answers 表由于某种原因没有真正被识别。我确实更改了该表的名称及其外键引用。有缓存之类的吗?

任何人都可以帮助或指出我的新方法吗?

4

1 回答 1

0

是的,它看起来像一个缓存问题。清除 app/tmp/cache/models 中的模型缓存文件(或您正在使用的任何缓存引擎)

于 2012-11-13T18:11:00.517 回答