[转帖]Cannot add or update a child row: a foreign key _MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2176 | 回复: 0   主题: [转帖]Cannot add or update a child row: a foreign key         下一篇 
dansmall
注册用户
等级:新兵
经验:52
发帖:71
精华:0
注册:2011-10-27
状态:离线
发送短消息息给dansmall 加好友    发送短消息息给dansmall 发消息
发表于: IP:您无权察看 2014-11-26 11:32:49 | [全部帖] [楼主帖] 楼主

Cannot add or update a child row: a foreign key constraint fails (`myznt/answer`, CONSTRAINT `answer_ibfk_1` FOREIGN KEY (`qid`

MySQL5.0.15

一个问题表(question),一个回答表(answer)分别如下:

create table question
(
qid int auto_increment not null,
title VARCHAR(50),
content text,
itemid int,
subid int,
userid VARCHAR(50),
grade VARCHAR(50),
offerscore int,
status int,
questiontime datetime,
clickcount int,
acceptflag int,
commenflag int,
primary key (qid)
);
create table answer
(
aid int auto_increment not null,
quesans VARCHAR(50),
userid VARCHAR(50),
grade VARCHAR(50),
anstime datetime,
status int,
qid int,
primary key (aid) ,
foreign key (qid) references question(qid) on delete cascade
);


question表对应地hibernate3.1的映射文件为:Question.hbm.xml,内容如下:

<hibernate-mapping>
<class name="com.iwtxokhtd.vo.Question" table="question">
<id name="qid" type="java.lang.Integer">
<column name="qid" />
<generator class="native" />
</id>
<property name="title" type="java.lang.String">
<column name="title" length="50" />
</property>
<property name="content" type="java.lang.String">
<column name="content" length="65535" />
</property>
<property name="itemid" type="java.lang.Integer">
<column name="itemid" />
</property>
<property name="subid" type="java.lang.Integer">
<column name="subid" />
</property>
<property name="userid" type="java.lang.String">
<column name="userid" length="50" />
</property>
<property name="grade" type="java.lang.String">
<column name="grade" length="50" />
</property>
<property name="offerscore" type="java.lang.Integer">
<column name="offerscore" />
</property>
<property name="status" type="java.lang.Integer">
<column name="status" />
</property>
<property name="questiontime" type="java.util.Date">
<column name="questiontime" length="19" />
</property>
<property name="clickcount" type="java.lang.Integer">
<column name="clickcount" />
</property>
<property name="acceptflag" type="java.lang.Integer">


--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论