EF migrations and timestamp column, cannot update/run

.net c# entity-framework entity-framework-6

Question

I accidentally didn't inherit from my auditableEntity class when creating an object in EF6. This class' setup looks like this.

public abstract class AuditableEntityConfig<TEntity> : BaseEntityConfig<TEntity> where TEntity : AuditableEntity
{
    public AuditableEntityConfig()
        : base()
    {

        this.Property(e => e.RowVersion)
            .IsRowVersion();

    }
}

Now that my object has been modified to inherit from this class, whenever I run my code, I always receive an error saying

Cannot alter column 'RowVersion' to be data type timestamp.

Is there any way I can prevent EF from attempting to set this column to be a timestamp? If not, may I suggest dropping the table and creating it from scratch?

1
4
2/26/2015 6:52:54 AM

Popular Answer

Replace one line AlterColumn with 2 lines DropColumn and AddColumn in Up() method.

        public override void Up()
        {
            DropColumn("dbo.Cities", "RowVersion", null);
            AddColumn("dbo.Cities", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
        }

        public override void Down()
        {
            AlterColumn("dbo.Cities", "RowVersion", c => c.Binary());
        }
3
2/28/2016 10:02:20 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow