NHibernate SchemaUpdate 再次添加现有外键?

发布于 2024-09-29 06:45:04 字数 560 浏览 0 评论 0原文

我正在使用 SchemaUpdate 将我的 hbms 与现有数据库同步。数据库最近基于 hbms 创建,并且是完全最新的。但是 SchemaUpdate 再次生成所有外键约束。

例如,假设您有 StudentTeacherStudent 与名为 ArtTeacherTeacher 存在关联。 ArtTeacher 是从 StudentTeacher 的外键。假设数据库是最新的,并且当前持有 StudentTeacher 及其外键关系。因此,HBMDatabase 是等效的。知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2024-10-06 06:45:04

秘诀是确保您指定外键的名称,否则 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文