Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate SchemaUpdate adding existing foreign keys again?

I'm using SchemaUpdate to synchronize my hbms with existing database. Database has recently created based on hbms and is completely up-to-date. But SchemaUpdate generates all foreign key constraints again.

For example suppose you have Student and Teacher. Student has association to Teacher with name ArtTeacher. ArtTeacher is a foreign key from Student to Teacher. Suppose database is up-to-date and currently holde Student, Teacher and their foreign key relation. So HBM and Database are equivalent. Know SchemaUpdate must not do anything but when I see its generated scripts, it re-produce that foreign key again.

Why this happens? Is there any way to avoid it?

like image 891
Afshar Mohebi Avatar asked Oct 28 '10 07:10

Afshar Mohebi


1 Answers

The secret is to ensure that you specify names for the foreign keys, or else NHibernate will generate a random name which won't match the existing schema.

(I fished this answer out of the Google Cache of Afshar's blog post).

like image 67
cbp Avatar answered Sep 20 '22 13:09

cbp