NHibernate SchemaUpdate 再次添加现有外键?
我正在使用 SchemaUpdate
将我的 hbms
与现有数据库同步。数据库最近基于 hbms
创建,并且是完全最新的。但是 SchemaUpdate
再次生成所有外键约束。
例如,假设您有 Student
和 Teacher
。 Student
与名为 ArtTeacher
的 Teacher
存在关联。 ArtTeacher
是从 Student
到 Teacher
的外键。假设数据库是最新的,并且当前持有 Student
、Teacher
及其外键关系。因此,HBM
和 Database
是等效的。知道 SchemaUpdate 不能执行任何操作,但是当我看到它生成的脚本时,它会再次重新生成该外键。
为什么会出现这种情况?有什么办法可以避免吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
秘诀是确保您指定外键的名称,否则 NHibernate 将生成一个与现有架构不匹配的随机名称。
(我从 Afshar 博客文章的 Google 缓存中找到了这个答案)。
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).