向MYSQL中插入数据出问题了
create table student(number varchar(10) not null primary key,name varchar(10) not null,loanNumber varchar(10),ID varchar(20) not null,sex varchar(5) not null,birthday varchar(50) not null,enterSchoolTime varchar(50) not null,address varchar(50),
postID varchar(10) not null,telNumber varchar(15),class varchar(50),academy varchar(50),major varchar(20),
loanType int,loanAmount int,loanState varchar(10))TYPE=INNODB;这是学生信息表
create table loan(loanNumber varchar(10) ,name varchar(10) not null,number varchar(10) not null ,
applyLoanTime varchar(20) not null,
class varchar(50),academy varchar(50),major varchar(20),
loanType int,loanAmount int,loanState varchar(10),primary key(number,loanNumber))TYPE=INNODB;这是学生贷款信息表
create unique index index_loan on loan(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState);
create unique index index_student on student(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState);
alter table loan add FOREIGN KEY (loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState)
REFERENCES student(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState)ON UPDATE CASCADE ON DELETE CASCADE;
以上是我创建的表:
我 在student表中插入了一行数据,我想修改loan表的loanNumber属性但是提示发生了SQLException异常,这是异常信息:Cannot add or update a child row: a foreign key constraint fails,本来我想利用级联属性来达到修改loan表中的属性进而可以自动的修改student表中的属性,但就是有问题,而删除一行loan表的记录可以,但student中对应的记录没删除,请问这是为什么,我不 是已经添加级联属性了嘛?
请各位高手们赐教,谢谢你们的帮助!