craftconomy3 icon indicating copy to clipboard operation
craftconomy3 copied to clipboard

java.sql.SQLException: Cannot add foreign key constraint

Open eyebrawl123 opened this issue 3 years ago • 5 comments

[13:28:26] [Server thread/INFO]: [com.zaxxer.hikari.HikariDataSource] HikariPool-1 - Starting... [13:28:26] [Server thread/INFO]: [com.zaxxer.hikari.HikariDataSource] HikariPool-1 - Start completed. [13:28:26] [Server thread/WARN]: java.sql.SQLException: Cannot add foreign key constraint [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347) [13:28:26] [Server thread/WARN]: at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025) [13:28:26] [Server thread/WARN]: at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) [13:28:26] [Server thread/WARN]: at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) [13:28:26] [Server thread/WARN]: at com.greatmancode.craftconomy3.storage.sql.MySQLEngine.(MySQLEngine.java:97) [13:28:26] [Server thread/WARN]: at com.greatmancode.craftconomy3.storage.StorageHandler.(StorageHandler.java:41) [13:28:26] [Server thread/WARN]: at com.greatmancode.craftconomy3.Common.initialiseDatabase(Common.java:361) [13:28:26] [Server thread/WARN]: at com.greatmancode.craftconomy3.Common.onEnable(Common.java:133) [13:28:26] [Server thread/WARN]: at com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader.onEnable(BukkitLoader.java:53) [13:28:26] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) [13:28:26] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:380) [13:28:26] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:483) [13:28:26] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:501) [13:28:26] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:415) [13:28:26] [Server thread/WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:591) [13:28:26] [Server thread/WARN]: at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:280) [13:28:26] [Server thread/WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1065) [13:28:26] [Server thread/WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:289) [13:28:26] [Server thread/WARN]: at java.lang.Thread.run(Thread.java:748)

This problem has existed since Ver.32.5.2 but everything works without any problems

eyebrawl123 avatar Apr 19 '21 14:04 eyebrawl123

Thanks for reporting this issue. Mh, this error occurs on every load (onEnable()) when the MySQLEngine checks for all tables. It executes the "CREATE TABLE IF NOT EXISTS" statements for each table on every startup (I may want to change this in the future) and it seems that it does not work with the exchange table.

@eyebrawl123 can you check if the exchange table exists in your database and if so: Can you check if the two constraints "fk_exchange_currencyfrom" and "fk_exchange_currencyto" exist?

  • CONSTRAINT `cc3_fk_exchange_currencyfrom` FOREIGN KEY (from_currency) REFERENCES cc3_currency (name) ON UPDATE CASCADE ON DELETE CASCADE
  • CONSTRAINT `fk_exchange_currencyto` FOREIGN KEY (to_currency) REFERENCES cc3_currency (name) ON UPDATE CASCADE ON DELETE CASCADE

pavog avatar Apr 19 '21 16:04 pavog

I didn't find "fk_exchange_currencyfrom" and "fk_exchange_currencyto" in any of the cc3 tables.

eyebrawl123 avatar Apr 19 '21 17:04 eyebrawl123

Thank you. Can you try to add them manually and let me know the error message (if you get one)?

pavog avatar Apr 19 '21 17:04 pavog

Hi, unfortunately I have no idea about databases and don't know how to do it. I neither know what nor where to copy anything. Sorry I would rather live with the message than break something because there are several thousand users in the database

eyebrawl123 avatar Apr 19 '21 18:04 eyebrawl123

Ok, thank you. Would you please contact me privately? [email protected]

pavog avatar Apr 20 '21 05:04 pavog