因此,我正在构建一个基于spring引导的api,当我连接到托管db的mariadb服务器时,我得到了以下异常。
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table pow2image add constraint FKfnn5r6ascraodeblk9mrkedfq foreign key (image_id) references Image (id)]
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:386)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:214)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 71 more
Caused by: java.sql.SQLException: Can't create table 'praze.#sql-db9_175' (errno: 150)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1552)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2607)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1480)
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)
... 81 more
这些是相关表的创建脚本
DROP TABLE IF EXISTS pow2image;
CREATE TABLE `pow2image` (
`pow_id` int(11) NOT NULL,
`image_id` int(11) NOT NULL,
PRIMARY KEY (`pow_id`,`image_id`),
CONSTRAINT `FKd134yk996sx2f8a9e4as75cyd` FOREIGN KEY (`pow_id`) REFERENCES `place_of_worship` (`id`),
CONSTRAINT `FKsk2761pm5gcx9dd09gnww1ord` FOREIGN KEY (`image_id`) REFERENCES `image` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS place_of_worship;
CREATE TABLE place_of_worship (
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(240) DEFAULT NULL,
address VARCHAR(240) DEFAULT NULL,
phone VARCHAR(20) DEFAULT NULL,
google_id VARCHAR(100) DEFAULT NULL,
description VARCHAR(300)
) ENGINE=INNODB;
DROP TABLE IF EXISTS image;
CREATE TABLE IF NOT EXISTS image (
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
server_location VARCHAR(255),
path_to_image VARCHAR(255),
upload_date DATETIME
) ENGINE=INNODB;
尽管当我在连接到本地托管的mysql服务器时构建项目时,项目构建没有错误。
感谢您的帮助。
更新:
+-----------------------------+--------------------+
| constraint_name | table_name |
+-----------------------------+--------------------+
| FK3ibpw0h9kwvc50b4i1jh8dl | users2profileimage |
| FK3ibpw0h9kwvc50b4i1jhwv8dl | users2review |
| FKhqe0if0vbqn7j3hd32bc1gkhi | users2review |
| FKhqe0if0vbqn7j3hd32bkhi | users2profileimage |
| FKo68tp3gfehrsjesas3eltvk9w | pow2review |
| FKrd83cby4x2n561nx477y46kk8 | pow2review |
| religion_ibfk_1 | religion |
| review_ibfk_1 | review |
| review_ibfk_2 | review |
+-----------------------------+--------------------+
我查询了数据库中的所有外键,看起来好像我得到了一个甚至不存在的键的错误?
1条答案
按热度按时间hpxqektj1#
我不确定,但我认为不可能为表'pow2image'创建foreign,因为您的引用有问题。