Question

I've added a string field to my hibernate persistent class, and restarted the application. It started SchemaUpgrade, and resulted in several errors like this one:

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)

The column was added to the DB though. And everything seem to be working fine. Except fot those errors, popping out every time, I start the application.

What can I do to help it create those indexes? DB is MySQL, hibernate version is 3.0.

Was it helpful?

Solution

It doesn't sounds like a Hibernate problem. If you try to run manually, you'll see that you'll get the same problem. By looking at MySQL manuals, I see that "errno: 150" means:

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

OTHER TIPS

Also make sure that the TABLE_COLLATION between the referenced and referent columns are the same...otherwise you also get that error.

For me the problem was resolved by changing all the tables Engine to InnoDB.

Here is how to do it manually :

https://stackoverflow.com/a/9492183/1988704

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top