【问题标题】:NHibernate SchemaUpdate recreate DB, but not updateNHibernate SchemaUpdate 重新创建数据库,但不更新
【发布时间】:2013-05-22 11:20:00
【问题描述】:

我实施了数据库迁移,但卡住了。我使用这段代码来检查 SchemaUpdate 的脚本:

List<string> scripts = new List<string>(1000);
_cfg.BuildMappings();

SchemaUpdate schemaUpdate = new SchemaUpdate(_cfg);
schemaUpdate.Execute(str =>
{
   scripts.Add(str);
}, true);

我的数据库包含几个表。我添加了新的测试表。我预计该脚本将仅包含一项用于表创建的项目。但令我惊讶的是,他创建了所有表格。

如何解决这个问题?

更新

SchemaUpdate 为除测试表之外的所有项目引发异常。

There is already an object named XXX

【问题讨论】:

  • 您使用哪个数据库驱动程序?连接字符串是否正确?
  • @Firo driver=NHibernate.Driver.SqlClientDriver 和连接字符串很好。连接字符串 = Server=(local);Database=MyDataBase;user=admin;password=pass;
  • 使用 new MsSqlDataBaseSchema(session.Connection).GetTables(catalog, schemaPattern, new [] {"TABLE", "VIEW"}) 查看 schemaupdate 看到的表#
  • @Firo DB=( 中没有表。我还在 Configuration 类中尝试了 ValidateSchema ,它说表丢失了。你知道如何处理这个问题吗?

标签: c# nhibernate schema database-migration


【解决方案1】:

找到解决方案。这是我的错。我将所有表命名为 [Table]。 NHibernate 比较 [Table] 和 Table。这就是为什么它试图创建它们。感谢 Firo 的建议)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多