I added the fallowing Fluent API into my context.
protected override void OnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Entity<MainClass>().HasOptional(a => a.simpleItems).WithOptionalDependent().WillCascadeOnDelete(true);
}
add-migration
resulted in the fallowing migration:
public override void Up()
{
DropForeignKey("dbo.SimpleItems", "MainClass_id", "dbo.MainClasses");
DropIndex("dbo.SimpleItems", new[] { "MainClass_id" });
RenameColumn(table: "dbo.MainClasses", name: "MainClass_id", newName: "simpleItems_id");
CreateIndex("dbo.MainClasses", "simpleItems_id");
AddForeignKey("dbo.MainClasses", "simpleItems_id", "dbo.SimpleItems", "id", cascadeDelete: true);
DropColumn("dbo.SimpleItems", "MainClass_id");
}
But I'm not able to perform the migration. when i type update-database -verbose
I got the fallowing error:
Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong.
How can i fix it?
P.S. Using verbose Im able to see that the error occurs when the update-database are executes creates this line:
EXECUTE sp_rename @objname = N'dbo.MainClasses.MainClass_id', @newname = N'simpleItems_id', @objtype = N'COLUMN'
P.S. If I remove the all the migrations and enable a new migration from scratch, the database is successfully updated. The problem exists specifically with this migration above.