Ich bestätige, dass dies hier mehrmals gestellt wurde, und ich habe viele Antworten durchgesehen.MySQL Errno 150 (falscher Fremdschlüssel) für CREATE TABLE
Ich weiß, dass errno150 verweist auf eine Tabelle mit einem falschen Fremdschlüssel, und ich habe eine vorherige Antwort here gesehen. Ich habe dort alle Zustände überprüft und kann das nicht herausfinden. Ich weiß nicht, ob ich etwas Offensichtliches vermisse.
Das die Java implentation von MySQL verwendet, habe ich eine switch-Anweisung, die wie so zwei Tabellen (im Moment) erzeugt:
//Creates the table with the name given to the function and adds all fields & keys
switch(tableName){
case "Address":
stmt.executeUpdate("CREATE TABLE Address(houseNo INT(4) NOT NULL, "
+ "firstLine VARCHAR(30) NOT NULL, "
+ "secondLine VARCHAR(30), "
+ "city VARCHAR(25) NOT NULL, "
+ "county VARCHAR(25) NOT NULL, "
+ "postCode VARCHAR(7) NOT NULL, "
+ "PRIMARY KEY (houseNo, postCode))");
break;
case "Patient":
stmt.executeUpdate("CREATE TABLE Patient(patientID INT(8) NOT NULL PRIMARY KEY AUTO_INCREMENT, "
+ "title VARCHAR (10) NOT NULL, "
+ "forename VARCHAR(15) NOT NULL, "
+ "surname VARCHAR(25) NOT NULL, "
+ "dob DATE NOT NULL, "
+ "phoneNo CHAR(11) NOT NULL, "
+ "houseNo INT(4) NOT NULL, "
+ "postCode VARCHAR(7) NOT NULL, "
+ "amountOwed DECIMAL(5,2) NOT NULL, "
+ "FOREIGN KEY (houseNo) REFERENCES Address (houseNo), "
+ "FOREIGN KEY (postCode) REFERENCES Address (postCode))");
break;
}
Adresse erzeugt fein (keine Fremdschlüssel), Patient errno150 gibt . Gleiche Engine, gleicher Zeichensatz, gleicher Datentyp (sogar kopiert, um 100% sicher zu sein), neu erstellte (leere) Tabellen, beide nicht temporär.
Danke.
P.S. Ich kann SHOW ENGINE INNODB STATUS
nicht verwenden, da ich keine ausreichend hohe Berechtigungsstufe habe.
Vollfehlermeldung:
java.sql.SQLException: Can't create table 'team.Patient' (errno: 150)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1540)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2595)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1468)
at uk.team.App.makeTable(App.java:146)
at uk.team.App.setupEnviro(App.java:80)
at uk.team.App.access$1(App.java:45)
at uk.team.App$1.run(App.java:33)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
können Sie den gesamten Fehler einfügen? Was hast du in der mysql-Befehlszeile? – Jordon
@ShivaShinde Es ist über Java erstellt, ich kann den vollständigen Fehler im ursprünglichen Beitrag hinzufügen. –
Bitte fügen Sie den gesamten Fehler hinzu !! – Jordon