I have a asp.net 5 project and EF version is 7.0.0-rc1-final.I have a custom table named "Website" but can't create a FK to identity user table. There are some code snippet

public class ApplicationUser : IdentityUser
        public virtual ICollection<Website> Website { get; set; }        

public class Website
    public int Id { get; set; }

    public string Url { get; set; }

    public string ApplicationUserId { get; set; }

    public virtual ApplicationUser ApplicationUser { get; set; }

builder.Entity<Website>(entity =>
     entity.HasOne(w => w.ApplicationUser)
           .WithMany(w => w.Website)
           .HasForeignKey(w => w.ApplicationUserId);                            
     entity.Property(w => w.Url).HasMaxLength(200).IsRequired();

I follow the ASP.NET 5 Application to New Database use dnx ef database update to update db but got error

Foreign key 'FK_Website_ApplicationUser_UserId' references invalid column 'UserI
d' in referenced table 'AspNetUsers'.
Could not create constraint or index. See previous errors.

BTW. I want to do this by fluent API

Related posts

Recent Viewed