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)

插入不了。求答案

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

外键约束出错了 你的SQL和数据库表的设计冲突了

我感觉你应该先插入主表的外键值,然后再插入从表的主键值就没事了,因为外键只有在主表里出现过才能插入,不知道你懂没有懂我的意思?