Irakli Lekishvili
Irakli Lekishvili

Reputation: 34158

Fluent nHibernate SchemaUpdate not working

I`m using Fluent nHibernate code first, I had Nullable column, then changed to .Not.Nullable() but my column is still Nullable

Here is my configuration

 public override void Load()
        {
            Bind<ISessionFactory>().ToMethod(x =>
             {
                 var factory = Fluently.Configure()
                     .Database(MsSqlConfiguration.MsSql2008.ConnectionString
                         (c => c.FromConnectionStringWithKey("DefaultConnection")))
                     .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Users>()
                         .Conventions.Add(PrimaryKey.Name.Is(p => "Id"), ForeignKey.EndsWith("Id"))
                         .Conventions.Setup(c => c.Add(AutoImport.Never())))
                     .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(true, true));

                 return factory.BuildSessionFactory();
             }).InSingletonScope();
        }

Upvotes: 0

Views: 929

Answers (1)

Firo
Firo

Reputation: 30813

AFAIK SchemaUpdate will not touch existing columns because it won't handle edge cases, e.g. what happens if the column already contains null values?

Your options:

  • add the notnull constraint manually
  • recreate the Schema using SchemaExport

Upvotes: 2

Related Questions