qq_31634593 2015-12-12 15:25 采纳率: 0%
浏览 1665

sql插入插入不了,这个是怎么回事?

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO mtc_pc_albumrelease(release_id,photo_id,update_user_name,yn_release,sort_num,update_time ) VALUES(?,?,?,?,?,?)]; Cannot add or update a child row: a foreign key constraint fails (maitian.mtc_pc_albumrelease, CONSTRAINT mtc_pc_albumrelease_ibfk_1 FOREIGN KEY (release_id) REFERENCES mtc_pc_album (album_id)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (maitian.mtc_pc_albumrelease, CONSTRAINT mtc_pc_albumrelease_ibfk_1 FOREIGN KEY (release_id) REFERENCES mtc_pc_album (album_id))
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:243)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:943)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTempla

Cannot add or update a child row: a foreign key constraint fails (`maitian`.`mtc_pc_albumrelease`, CONSTRAINT `mtc_pc_albumrelease_ibfk_1` FOREIGN KEY (`release_id`) REFERENCES `mtc_pc_album` (`album_id`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

插入不了。求答案
  • 写回答

3条回答

  • 明月夜ll 2015-12-12 16:17
    关注

    从异常上看:表mtc_pc_albumrelease的release_id这一列和表mtc_pc_album的album_id这一列有外键联系。
    表mtc_pc_albumrelease为从表,表mtc_pc_album为主表。从表中不能出现主表中不存在的数据。

    评论

报告相同问题?