我已将一个字符串字段添加到我的 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/