SchemaExport、NHibernate 和删除外键
我正在构建映射,然后使用架构导出来更新我的数据库。 但是,如果我删除映射中的关联,因为它不再在映射中,所以当我运行 SchemaExport 时,它不会删除已删除关联的外键。 这意味着它无法删除与该外键关联的表。 这进一步意味着它无法重新创建表,并且我收到“数据库中已有一个名为 Foo 的对象”异常。 有没有办法通过 Schema Export 暴力删除表?
I am building my mapping and then using schema export to update my DB. However, if I delete an association in my mapping, since it's no longer in the mapping, when I run SchemaExport, it will not delete the foreign key for the deleted association. This means that it then fails to drop the table associated with that foreign key. Which further means that it can't recreate the table and I get a "There is already an object named Foo in the database" exception. Is there any way to brute delete the table via Schema Export?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最干净的方法是使用旧的 nhibernate 配置执行 SchemaExport.Drop,然后使用新的配置进行创建。
或者,您可以删除并重新创建数据库本身,下面是在 SQL Server Express 文件级别执行此操作的示例:http://nicholas.piasecki.name/blog/2010/01/integration-testing-with-sql-server-express -2008-nhibernate-and-mstest/
The cleanest way is to do SchemaExport.Drop with the old nhibernate configuration, then create with the new one.
Alternatively you could drop and recreate the database itself, here's an example which does this at file level for SQL Server Express: http://nicholas.piasecki.name/blog/2010/01/integration-testing-with-sql-server-express-2008-nhibernate-and-mstest/