Entity Framework can't migrate MaxLength value when column has index -
i try change maxlength property 100 50 , got exception says
"the index 'ix_singers_name' dependent on column 'name'. alter table alter column name failed because 1 or more objects access column."
mode :
public class singer : namedentity { [maxlength(50)] // 100 public override string name { get; set; } }
as understand, entity framework needs alter table change can't alter table because index exist on name property. how can make possible entity framework migrations ?
i can possibly drop index in migration change maxlength in next migration , create index last migration again. believe there should exist easy way change attribute value.
in sql server, indexes pretty tables themselves. if you've got column in index, both index , table need modified. agree ef migrations scaffolded add index (e.g. foreign key) should take care of removing , reapplying index. however, in instance index have had have been added manually. therefore need maintained manually in migration. note can done in single migration:
public override void up() { dropindex("dbo.singer", new []{"name"}); /* code alter table */ createindex("dbo.singer", "name"); }
don't forget put in both up()
, down()
methods.
Comments
Post a Comment