Migrating to 2.1 adds extra indexes and foreign keys
See original GitHub issueI have the following data structure:
public class Foo {
public long Id;
public virtual ICollection<Bar> Bars { get; set; }
}
public abstract class Bar {
// properties
}
public class Bar1 : Bar {
public long FooId { get; set; }
public virtual Foo Foo { get; set; }
}
public class Bar2 : Bar {
public long FooId { get; set; }
public long Foo Foo { get; set; }
}
// these two lines are inside the OnModelCreating method in the context
modelBuilder.Entity<Bar1>.Property(x => x.FooId).HasColumnName("FooId");
modelBuilder.Entity<Bar2>.Property(x => x.FooId).HasColumnName("FooId");
The initial migration for the code was generated using 2.0 and the Bar
table had only one index and one foreign key. After making changes to the model, the first migration with 2.1 added another foreign key and index to the same property.
Is this normal, because I couldn’t find anything about this change.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to stop EF Core from indexing all foreign keys
As documented in questions like Entity Framework Indexing ALL foreign key columns, EF Core seems to automatically generate an index for every ...
Read more >Migration: Changing an index that is part of an FK ...
Changed some indexes from being unique to non-unique, but since they all are in foreign key constraints they won't update since the FK's ......
Read more >Active Record Migrations
This migration adds a table called products with a string column called name and ... References are a shorthand for creating columns, indexes,...
Read more >Loose foreign keys
When the loose foreign key definition is no longer needed (parent table is removed, or FK is restored), we need to remove the...
Read more >Using a PostgreSQL database as an AWS DMS source
You can migrate data from one or many PostgreSQL databases using AWS DMS. ... with the same name and recreates the tables, indexes,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dushkostanoeski You need to move the navigation
Foo
to the base -Bar
to indicate that both derived relationships should be represented by a single FK. Otherwise you can just configure the FK name on both relationships explicitly to the same value.@AndriySvyryd I just upgraded to the 2.1.0 release, and the migration still added the extra indexes and foreign keys.