3

I had a field with following attributes:

[Column("Name")]
[StringLength(50)]
public string Name { get; set; }

The migration for this field looked like this:

CreateTable(
"dbo.TEST",
c => new
{
     Id = c.Int(nullable: false),
     Name = c.String(maxLength: 50),
})
.PrimaryKey(t => t.Id)
.Index(t => t.Id
);

Then I changed the field like this:

[Column("Test_Name")]
[StringLength(255)]
public string TestName { get; set; }

and executed Add-Migration, but the StringLength change was not included it is still NVARCHAR2(50) in my Oracle DB and the new migration looks like this:

RenameColumn(table: "dbo.TEST", name: "Name", newName: "Test_Name");

Is this a common problem?

What do I need to do so that the length is also changed in the DB?

Palmi
  • 2,381
  • 5
  • 28
  • 65
  • You may need to hack the Up() code: http://stackoverflow.com/questions/28299080/how-to-change-size-of-existing-column-using-entity-framework-6-code-first – Steve Greene Jul 20 '16 at 17:46

1 Answers1

0

How many migrations do you have already? We started to experience bugs in the creation of migration scripts after accumulating ~20 migrations. If you have more than 10 migrations try to consolidate them. When I did the consolidation the generation of migration scripts started to work fine.

Community
  • 1
  • 1
Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70