mysql - Hibernate Schema 更新问题

标签 mysql hibernate indexing mysql-error-1005

我已将一个字符串字段添加到我的 hibernate 持久类中,并重新启动了应用程序。它启动了 SchemaUpgrade,并导致了几个类似这样的错误:

2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table table_name add index FKCD10932052C35B33 (previewExample_id), add constraint FKCD10932052C35B33 foreign key (previewExample_id) references preview (id)
2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Can't create table 'dbName.#sql-59c_1cc' (errno: 150)

虽然该列已添加到数据库中。一切似乎都运行良好。除了那些错误,每次都会弹出,我启动应用程序。

我可以做些什么来帮助它创建这些索引? DB是MySQL,hibernate版本是3.0。

最佳答案

这听起来不像是 Hibernate 问题。如果您尝试手动运行,您会发现您会遇到同样的问题。通过查看 MySQL 手册,我看到“errno: 150”表示:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

关于mysql - Hibernate Schema 更新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4885434/

相关文章:

mysql - 我可以告诉Mysql哪些索引保留在内存中而不管其他索引吗?

php - 使用 MYSQL 通过 ODBC 更新 Filemaker Pro

php - 按关键字搜索 SQL 查询

python - 如何使用 django 自动创建 uuid 列

mongodb - Azure cosmos DB 3.6 Mongo 不支持具有嵌入字段的复合索引

c - 为什么在引用具有越界索引的字符串时不会产生错误?

mysql - 根据状态选择记录(如果存在)

java - 使用 Springs 事务管理与使用 hibernate 的好处

java - 如何更改 hibernate 约束名称生成?

mysql - 陷入在 Hibernate 中编写 HQL/MySQL 查询的困境