私は2つのテーブルを持っています。最初のテーブルpatientenは自動増分IDを持ちます。 1人の "患者"には複数の "gebit"があります。 idPatientは2つのテーブルからの外部キーです。他のテーブルからの自動インクリメントに基づいてデータベースに外部キーを入力します
patienten:
がgebit:
今私は "gebit" テーブルを埋めるためにしたいが、私はエラーを得続けます。
マイコード:
public void addTandenToDatabase(int fdi, String voorstelling, String toestand) {
String insertSql = "insert into gebit(fdi, voorstelling, toestand) values (:fdiVal, :voorstellingVal, :toestandVal)";
try (Connection con = sql2o.open()) {
con.setRollbackOnException(false);
con.createQuery(insertSql)
.addParameter("fdiVal", fdi)
.addParameter("voorstellingVal", voorstelling)
.addParameter("toestandVal", toestand)
.executeUpdate();
}
}
私が取得エラー:
public void addTandenToDatabase(int fdi, String voorstelling, String toestand) {
String insertSql = "insert into gebit(idPatient, fdi, voorstelling, toestand) values (:idVal, :fdiVal, :voorstellingVal, :toestandVal)";
try (Connection con = sql2o.open()) {
con.setRollbackOnException(false);
con.createQuery(insertSql)
.addParameter("fdiVal", fdi)
.addParameter("idVal", fdi)
.addParameter("voorstellingVal", voorstelling)
.addParameter("toestandVal", toestand)
.executeUpdate();
}
}
:
私は私がgebitにidPatientにVALUを追加する第二の方法を試してみましたしかし、それは私にこのエラーを与える:
Error in executeUpdate, Cannot add or update a child row: a foreign key constraint fails (`toondoesselaere`.`gebit`, CONSTRAINT `idPatient` FOREIGN KEY (`idPatient`) REFERENCES `patienten` (`idPatient`) ON DELETE NO ACTION ON UPDATE NO ACTION)
gebitにidValという列がありますか? – Unknown
いいえ、列idPatient – Skupaj