How to Create Tables Automatically in Code First Approach using PostgreSql
I am trying to create the tables using code first approach with postgresql database. My DB context is below.While doing migration i am getting the below error.
Cannot use table 'AspNetRoles' for entity type 'AspNetRole' since it is being used for entity type 'IdentityRole' and there is no relationship between their primary keys.
How to resolve this?
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public DbSet<Project> Projects get; set;
public DbSet<Story> Stories get; set;
public DbSet<Epic> Epics get; set;
public DbSet<Favourite> Favourites get; set;
public DbSet<Priority> Priorities get; set;
public DbSet<ProjectPermission> ProjectPermission get; set;
public DbSet<Theme> Themes get; set;
public DbSet<AspNetRole> AspNetRoles get; set;
public DbSet<AspNetRoleClaim> AspNetRoleClaims get; set;
public DbSet<AspNetUser> AspNetUsers get; set;
public DbSet<AspNetUserClaim> AspNetUserClaims get; set;
public DbSet<AspNetUserLogin> AspNetUserLogins get; set;
public DbSet<AspNetUserToken> AspNetUserTokens get; set;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
builder.Entity<AspNetUserToken>(entity =>
entity.HasKey(e => e.UserId);
entity.HasKey(e => e.LoginProvider);
entity.HasKey(e => e.Name);
);
builder.Entity<AspNetRole>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetRoleClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUser>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserLogin>(entity =>
entity.HasKey(e => e.ProviderKey);
entity.HasKey(e => e.LoginProvider);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_AspNetUserLoginUserId");
);
builder.Entity<Project>(entity =>
entity.HasKey(e => e.ProjectId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ProjectCreatedBy");
entity.HasIndex(e => e.Owner)
.HasName("fki_FK_ProjectOwner");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Projects)
.HasForeignKey(d => d.CreatedBy)
.HasForeignKey(a => a.Owner)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectCreatedBy");
);
builder.Entity<Story>(entity =>
entity.HasKey(e => e.StoryId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_StoryProjectId");
entity.HasIndex(e => e.ThemeId)
.HasName("fki_FK_StoryThemeId");
entity.HasIndex(e => e.EpicId)
.HasName("fki_FK_StoryEpicId");
entity.HasIndex(e => e.PriorityId)
.HasName("fki_FK_StoryPriorityId");
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_StoryCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryProjectId");
entity.HasOne(d => d.Epic)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.EpicId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryEpicId");
entity.HasOne(d => d.Theme)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ThemeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryThemeId");
entity.HasOne(d => d.Priority)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.PriorityId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryPriorityId");
);
builder.Entity<Epic>(entity =>
entity.HasKey(e => e.EpicId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_EpicCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_EpicProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicProjectId");
);
builder.Entity<Favourite>(entity =>
entity.HasKey(e => e.FavouriteId);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_FavouriteUserId");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_FavouriteProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.Favourites)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_FavouriteProjectId");
);
builder.Entity<Priority>(entity =>
entity.HasKey(e => e.PriorityId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_PriorityCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Priorities)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_PriorityCreatedBy");
);
builder.Entity<ProjectPermission>(entity =>
entity.HasKey(e => e.PermissionId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ProjectPermissionProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.ProjectPermissions)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectPermissionProjectId");
);
builder.Entity<Theme>(entity =>
entity.HasKey(e => e.ThemeId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ThemesCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ThemesProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesProjectId");
);
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
postgresql asp.net-core-2.0
add a comment |
I am trying to create the tables using code first approach with postgresql database. My DB context is below.While doing migration i am getting the below error.
Cannot use table 'AspNetRoles' for entity type 'AspNetRole' since it is being used for entity type 'IdentityRole' and there is no relationship between their primary keys.
How to resolve this?
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public DbSet<Project> Projects get; set;
public DbSet<Story> Stories get; set;
public DbSet<Epic> Epics get; set;
public DbSet<Favourite> Favourites get; set;
public DbSet<Priority> Priorities get; set;
public DbSet<ProjectPermission> ProjectPermission get; set;
public DbSet<Theme> Themes get; set;
public DbSet<AspNetRole> AspNetRoles get; set;
public DbSet<AspNetRoleClaim> AspNetRoleClaims get; set;
public DbSet<AspNetUser> AspNetUsers get; set;
public DbSet<AspNetUserClaim> AspNetUserClaims get; set;
public DbSet<AspNetUserLogin> AspNetUserLogins get; set;
public DbSet<AspNetUserToken> AspNetUserTokens get; set;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
builder.Entity<AspNetUserToken>(entity =>
entity.HasKey(e => e.UserId);
entity.HasKey(e => e.LoginProvider);
entity.HasKey(e => e.Name);
);
builder.Entity<AspNetRole>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetRoleClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUser>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserLogin>(entity =>
entity.HasKey(e => e.ProviderKey);
entity.HasKey(e => e.LoginProvider);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_AspNetUserLoginUserId");
);
builder.Entity<Project>(entity =>
entity.HasKey(e => e.ProjectId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ProjectCreatedBy");
entity.HasIndex(e => e.Owner)
.HasName("fki_FK_ProjectOwner");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Projects)
.HasForeignKey(d => d.CreatedBy)
.HasForeignKey(a => a.Owner)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectCreatedBy");
);
builder.Entity<Story>(entity =>
entity.HasKey(e => e.StoryId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_StoryProjectId");
entity.HasIndex(e => e.ThemeId)
.HasName("fki_FK_StoryThemeId");
entity.HasIndex(e => e.EpicId)
.HasName("fki_FK_StoryEpicId");
entity.HasIndex(e => e.PriorityId)
.HasName("fki_FK_StoryPriorityId");
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_StoryCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryProjectId");
entity.HasOne(d => d.Epic)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.EpicId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryEpicId");
entity.HasOne(d => d.Theme)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ThemeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryThemeId");
entity.HasOne(d => d.Priority)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.PriorityId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryPriorityId");
);
builder.Entity<Epic>(entity =>
entity.HasKey(e => e.EpicId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_EpicCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_EpicProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicProjectId");
);
builder.Entity<Favourite>(entity =>
entity.HasKey(e => e.FavouriteId);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_FavouriteUserId");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_FavouriteProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.Favourites)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_FavouriteProjectId");
);
builder.Entity<Priority>(entity =>
entity.HasKey(e => e.PriorityId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_PriorityCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Priorities)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_PriorityCreatedBy");
);
builder.Entity<ProjectPermission>(entity =>
entity.HasKey(e => e.PermissionId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ProjectPermissionProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.ProjectPermissions)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectPermissionProjectId");
);
builder.Entity<Theme>(entity =>
entity.HasKey(e => e.ThemeId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ThemesCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ThemesProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesProjectId");
);
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
postgresql asp.net-core-2.0
add a comment |
I am trying to create the tables using code first approach with postgresql database. My DB context is below.While doing migration i am getting the below error.
Cannot use table 'AspNetRoles' for entity type 'AspNetRole' since it is being used for entity type 'IdentityRole' and there is no relationship between their primary keys.
How to resolve this?
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public DbSet<Project> Projects get; set;
public DbSet<Story> Stories get; set;
public DbSet<Epic> Epics get; set;
public DbSet<Favourite> Favourites get; set;
public DbSet<Priority> Priorities get; set;
public DbSet<ProjectPermission> ProjectPermission get; set;
public DbSet<Theme> Themes get; set;
public DbSet<AspNetRole> AspNetRoles get; set;
public DbSet<AspNetRoleClaim> AspNetRoleClaims get; set;
public DbSet<AspNetUser> AspNetUsers get; set;
public DbSet<AspNetUserClaim> AspNetUserClaims get; set;
public DbSet<AspNetUserLogin> AspNetUserLogins get; set;
public DbSet<AspNetUserToken> AspNetUserTokens get; set;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
builder.Entity<AspNetUserToken>(entity =>
entity.HasKey(e => e.UserId);
entity.HasKey(e => e.LoginProvider);
entity.HasKey(e => e.Name);
);
builder.Entity<AspNetRole>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetRoleClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUser>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserLogin>(entity =>
entity.HasKey(e => e.ProviderKey);
entity.HasKey(e => e.LoginProvider);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_AspNetUserLoginUserId");
);
builder.Entity<Project>(entity =>
entity.HasKey(e => e.ProjectId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ProjectCreatedBy");
entity.HasIndex(e => e.Owner)
.HasName("fki_FK_ProjectOwner");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Projects)
.HasForeignKey(d => d.CreatedBy)
.HasForeignKey(a => a.Owner)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectCreatedBy");
);
builder.Entity<Story>(entity =>
entity.HasKey(e => e.StoryId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_StoryProjectId");
entity.HasIndex(e => e.ThemeId)
.HasName("fki_FK_StoryThemeId");
entity.HasIndex(e => e.EpicId)
.HasName("fki_FK_StoryEpicId");
entity.HasIndex(e => e.PriorityId)
.HasName("fki_FK_StoryPriorityId");
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_StoryCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryProjectId");
entity.HasOne(d => d.Epic)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.EpicId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryEpicId");
entity.HasOne(d => d.Theme)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ThemeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryThemeId");
entity.HasOne(d => d.Priority)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.PriorityId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryPriorityId");
);
builder.Entity<Epic>(entity =>
entity.HasKey(e => e.EpicId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_EpicCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_EpicProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicProjectId");
);
builder.Entity<Favourite>(entity =>
entity.HasKey(e => e.FavouriteId);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_FavouriteUserId");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_FavouriteProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.Favourites)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_FavouriteProjectId");
);
builder.Entity<Priority>(entity =>
entity.HasKey(e => e.PriorityId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_PriorityCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Priorities)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_PriorityCreatedBy");
);
builder.Entity<ProjectPermission>(entity =>
entity.HasKey(e => e.PermissionId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ProjectPermissionProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.ProjectPermissions)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectPermissionProjectId");
);
builder.Entity<Theme>(entity =>
entity.HasKey(e => e.ThemeId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ThemesCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ThemesProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesProjectId");
);
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
postgresql asp.net-core-2.0
I am trying to create the tables using code first approach with postgresql database. My DB context is below.While doing migration i am getting the below error.
Cannot use table 'AspNetRoles' for entity type 'AspNetRole' since it is being used for entity type 'IdentityRole' and there is no relationship between their primary keys.
How to resolve this?
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public DbSet<Project> Projects get; set;
public DbSet<Story> Stories get; set;
public DbSet<Epic> Epics get; set;
public DbSet<Favourite> Favourites get; set;
public DbSet<Priority> Priorities get; set;
public DbSet<ProjectPermission> ProjectPermission get; set;
public DbSet<Theme> Themes get; set;
public DbSet<AspNetRole> AspNetRoles get; set;
public DbSet<AspNetRoleClaim> AspNetRoleClaims get; set;
public DbSet<AspNetUser> AspNetUsers get; set;
public DbSet<AspNetUserClaim> AspNetUserClaims get; set;
public DbSet<AspNetUserLogin> AspNetUserLogins get; set;
public DbSet<AspNetUserToken> AspNetUserTokens get; set;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
builder.Entity<AspNetUserToken>(entity =>
entity.HasKey(e => e.UserId);
entity.HasKey(e => e.LoginProvider);
entity.HasKey(e => e.Name);
);
builder.Entity<AspNetRole>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetRoleClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUser>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserClaim>(entity =>
entity.HasKey(e => e.Id);
);
builder.Entity<AspNetUserLogin>(entity =>
entity.HasKey(e => e.ProviderKey);
entity.HasKey(e => e.LoginProvider);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_AspNetUserLoginUserId");
);
builder.Entity<Project>(entity =>
entity.HasKey(e => e.ProjectId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ProjectCreatedBy");
entity.HasIndex(e => e.Owner)
.HasName("fki_FK_ProjectOwner");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Projects)
.HasForeignKey(d => d.CreatedBy)
.HasForeignKey(a => a.Owner)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectCreatedBy");
);
builder.Entity<Story>(entity =>
entity.HasKey(e => e.StoryId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_StoryProjectId");
entity.HasIndex(e => e.ThemeId)
.HasName("fki_FK_StoryThemeId");
entity.HasIndex(e => e.EpicId)
.HasName("fki_FK_StoryEpicId");
entity.HasIndex(e => e.PriorityId)
.HasName("fki_FK_StoryPriorityId");
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_StoryCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryProjectId");
entity.HasOne(d => d.Epic)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.EpicId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryEpicId");
entity.HasOne(d => d.Theme)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.ThemeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryThemeId");
entity.HasOne(d => d.Priority)
.WithMany(p => p.Stories)
.HasForeignKey(d => d.PriorityId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_StoryPriorityId");
);
builder.Entity<Epic>(entity =>
entity.HasKey(e => e.EpicId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_EpicCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_EpicProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Epics)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_EpicProjectId");
);
builder.Entity<Favourite>(entity =>
entity.HasKey(e => e.FavouriteId);
entity.HasIndex(e => e.UserId)
.HasName("fki_FK_FavouriteUserId");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_FavouriteProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.Favourites)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_FavouriteProjectId");
);
builder.Entity<Priority>(entity =>
entity.HasKey(e => e.PriorityId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_PriorityCreatedBy");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Priorities)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_PriorityCreatedBy");
);
builder.Entity<ProjectPermission>(entity =>
entity.HasKey(e => e.PermissionId);
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ProjectPermissionProjectId");
entity.HasOne(d => d.Project)
.WithMany(p => p.ProjectPermissions)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ProjectPermissionProjectId");
);
builder.Entity<Theme>(entity =>
entity.HasKey(e => e.ThemeId);
entity.HasIndex(e => e.CreatedBy)
.HasName("fki_FK_ThemesCreatedBy");
entity.HasIndex(e => e.ProjectId)
.HasName("fki_FK_ThemesProjectId");
entity.HasOne(d => d.AspNetUser)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesCreatedBy");
entity.HasOne(d => d.Project)
.WithMany(p => p.Themes)
.HasForeignKey(d => d.ProjectId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_ThemesProjectId");
);
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
postgresql asp.net-core-2.0
postgresql asp.net-core-2.0
asked Nov 14 '18 at 6:43
MelodyMelody
4551621
4551621
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think it's better to extend IdentityDbContext than to have the DbSets with the identity classes in your own class.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Test
public partial class ApplicationDbContext : IdentityDbContext<IdentityUser>
public DbSet<Project> Projects get; set;
...
public KassandraContext(DbContextOptions<KassandraContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(modelBuilder);
//Your stuff goes here...
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294480%2fhow-to-create-tables-automatically-in-code-first-approach-using-postgresql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think it's better to extend IdentityDbContext than to have the DbSets with the identity classes in your own class.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Test
public partial class ApplicationDbContext : IdentityDbContext<IdentityUser>
public DbSet<Project> Projects get; set;
...
public KassandraContext(DbContextOptions<KassandraContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(modelBuilder);
//Your stuff goes here...
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
|
show 1 more comment
I think it's better to extend IdentityDbContext than to have the DbSets with the identity classes in your own class.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Test
public partial class ApplicationDbContext : IdentityDbContext<IdentityUser>
public DbSet<Project> Projects get; set;
...
public KassandraContext(DbContextOptions<KassandraContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(modelBuilder);
//Your stuff goes here...
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
|
show 1 more comment
I think it's better to extend IdentityDbContext than to have the DbSets with the identity classes in your own class.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Test
public partial class ApplicationDbContext : IdentityDbContext<IdentityUser>
public DbSet<Project> Projects get; set;
...
public KassandraContext(DbContextOptions<KassandraContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(modelBuilder);
//Your stuff goes here...
I think it's better to extend IdentityDbContext than to have the DbSets with the identity classes in your own class.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Test
public partial class ApplicationDbContext : IdentityDbContext<IdentityUser>
public DbSet<Project> Projects get; set;
...
public KassandraContext(DbContextOptions<KassandraContext> options)
: base(options)
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(modelBuilder);
//Your stuff goes here...
answered Nov 14 '18 at 6:52
keuleJkeuleJ
1,90332038
1,90332038
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
|
show 1 more comment
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Hi keuleJ, Thanks for your update. Still i am getting the same error.
– Melody
Nov 14 '18 at 6:58
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
Did you remove all the DbSets with the Asp* Classes?
– keuleJ
Nov 14 '18 at 6:59
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
May be you should delete the tabels that you have an let them be regenerated. I have the following tables: AspNetRoleClaims AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers AspNetUserTokens
– keuleJ
Nov 14 '18 at 7:03
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
I have resolved the initial issue. Now i am getting the below error.Unable to determine the relationship represented by navigation property 'AspNetUser.Projects' of type 'ICollection<Project>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
– Melody
Nov 14 '18 at 7:16
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
You should use a Custom user class which extends IdentityUser and do the mappings for your classes there. Then let your ApplicationDbContext : IdentityDbContext<CustomUser>
– keuleJ
Nov 14 '18 at 7:29
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294480%2fhow-to-create-tables-automatically-in-code-first-approach-using-postgresql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown