Search code examples
c#nhibernateschemadatabase-migration

NHibernate SchemaUpdate recreate DB, but not update


I implemented DB migration, and stuck. I use this code to check SchemaUpdate's script:

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

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

My DB contains several tables. I added new Test table. I expected that script will contain only one item for table create. But I was surprised, that he create all tables.

How to fix this issue?

Update

SchemaUpdate throws exceptions for all items except Test table.

There is already an object named XXX

Solution

  • Finded solution. It is my mistake. I named all tables like [Table]. NHibernate compares [Table] and Table. That's why it tries to create them. Thanks Firo for advice)