Skip to content
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

ef migrations add always scaffolds Drop-/AddForeignKey for every FK #3761

Closed
Schlurcher opened this issue Nov 16, 2015 · 3 comments
Closed

Comments

@Schlurcher
Copy link

When scaffolding a new migration with dnx ef migration add I lately end up with a Drop-/AddForeignKey for every FK in my schema. Everytime. Even if I just add migrations back to back without model changes inbetween.

I don't know if this has anything to do with the fact that I renamed ApplicationUser to AppUser and explicitely added an AppRole. It seems to coincide with the first time this happened in a migration.

Here's the related part of my model:

public class DataContext : IdentityDbContext<AppUser, AppRole, string>
{
    public DbSet<Video> Videos { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<Video>(b =>
        {
            b.HasIndex(v => v.Slug).IsUnique();
        });

        builder.Entity<AppUser>(b =>
        {
            b.HasIndex(r => r.UserName).IsUnique();
            b.HasIndex(r => r.Email).IsUnique();
        });

        builder.Entity<AppRole>(b =>
        {
            b.HasIndex(r => r.Name).IsUnique();
        });
    }
}

public class AppUser : IdentityUser
{
    [Required]
    [Display(Name = "Benutzername")]
    public override string UserName { get; set; }

    [Required]
    [EmailAddress]
    [Display(Name = "E-Mail")]
    public override string Email { get; set; }

    [NotMapped]
    public ICollection<Character> Characters { get; set; }

    [NotMapped]
    public Character PrimaryCharacter { get; set; }
}

public class AppRole : IdentityRole
{
    [Required]
    public override string Name { get; set; }
}
@Schlurcher
Copy link
Author

After thinking about and playing around with this some more, maybe this is related to #3545 somehow?

@Schlurcher
Copy link
Author

Spent more time looking at the migrations and I think it's related to .OnDelete(DeleteBehavior.Cascade).

Unless .OnDelete(DeleteBehavior.Restrict) is specified, Up() is scaffolded as ReferentialAction.Cascade and Down() as .Restrict even if the FK was ON DELETE CASCADE.

@smitpatel
Copy link
Contributor

dupe of #3751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants