Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Closed Issue: Migrations :: migrating from database generated key (identity), to non-database generated key does not work [1550]

$
0
0
Repro:

Create simple model:

```
public class Foo
{
public int Id { get; set;}
public string Name { get; set; }

}

public class MyContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
}
```

Enable-Migrations
Add-Migration Mig1
Update-Database

Remove identity from the key column:

```
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Foo>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
```

Add-Migration Mig2
Update-Database

Result is that we silently succeed, but nothing happens on the database (i.e. Id is still Identity). If one tries to insert rows afterwards, we throw exception. We should either properly migrate table to non-identity or throw error that we don't support this change.
Same thing goes for migration the other way around.



Comments: Duplicate of https://entityframework.codeplex.com/workitem/509

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>