-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate foreign key generated after RC1 -> RC2 migration #5406
Comments
Explicit configuration should not be required. The only reason Migration would generate a different FK because it did not find it in ModelSnapshot file. Can you share ModelSnapshot file from RC1 time if you have. (It gets re-written after adding new migration so the present one might be different). ModelSnapshot file has changed over the time due to some bug fixes. I am not sure if the file from RC1 would work straight-forward with RC2. |
I think this is model building, not migrations. It looks like we are introducing a shadow FK for the relationship ( @beho can you share the complete model so that we can work out why it is doing this? |
Is there a private channel I could use for handing over model sources ? |
@beho feel free to email it thru (just include a reference to the issue #) |
I am also having this problem. I migrated from RC1 to RC2, and I see a shadow FK in the generated queries in sql profiler. I have a large data model, but this problems seems to occur only for one of my tables. I have a data model like this: Todo -|-----< Delegation Also, if I try to create a new migration with the |
@beho can you confirm that if you delete your RC1 migrations and then regenerate you get the correct thing? |
@rowanmiller I didn't get the right thing after deleting RC1 migrations. |
@rowanmiller I deleted both migrations and model snapshot but new clean-slate migration still contains both TicketBatchId and TicketBatchId1. Same with latest dev version from https://www.myget.org/gallery/aspnetvnext. |
Thanks @beho for the full repro. In case it helps you workaround the issue, the Here is a minimal repro: using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Repro5406
{
public class TicketBatch
{
[Key]
public int Id { get; set; }
// if the Guid property is present a shadow TicketBatchId1 FK is added to Ticket
// to support the one-to-many relationship
public Guid Guid { get; set; }
public List<Ticket> Tickets { get; set; }
}
public class Ticket
{
[Key]
public Guid Guid { get; set; }
public int TicketBatchId { get; set; }
public TicketBatch TicketBatch { get; set; }
}
public class ApplicationDbContext: DbContext
{
public DbSet<TicketBatch> Batches { get; set; }
public DbSet<Ticket> Tickets { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=(localdb)\\mssqllocaldb;Initial Catalog=repro5406:Integrated Security=yes");
}
}
} |
Assigning this to @smitpatel for investigation. |
Issue here is matching properties: |
We agreed this should be fixed in RTM with @smitpatel @bricelam and @ajcvickers. |
@divega I'm having the same issue in production. This is my relation:
And this is the table I'm getting: Although, when I perform an insert, the field "AutoId" is filled with the proper FK and "AutoId1" is ignored and is always null. Am I doing anything wrong or the bug haven't been fixed yet? |
@jcmontes95 I am not sure it is exactly the same issue as the original. If this is happening with RTM bits, can you please create a new issue with a full repro? |
@divega Indeed, it is happening with RTM bits. I'll create the new issue with its repro soon. |
Two simple models:
TicketBatch has two descendants that define only value (non-relationship) properties.
After manual migration of the project to 1.0.0-rc2-final, EF Core now wants to apply following in new migration:
When I explicitly state that the foreign key is TicketBatchId in ApplicationDbContext.OnModelCreating:
then new column is not added. But that should not be necessary as conventions are followed.
Only similar issue I found is #5344 but I did not dig deeper.
Thanks!
The text was updated successfully, but these errors were encountered: