i an using aspnet identity in one of my project my project entities are in different project where as identy is a seperate project(all knows)
i want to link some tables with identity i have linked thm successfully data is also entering appropriately in every table(identity + my project tables)
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion
// Database.SetInitializer
//Database.SetInitializer
//Database.SetInitializer
}
automaticmigrations are set to true in configuration.cs of migartion folder of this project
i have changed my identity db table names using this
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity
modelBuilder.Entity
modelBuilder.Entity
modelBuilder.Entity
modelBuilder.Entity
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
public virtual Employer Employer { get; set; }
public virtual Candidate Candidate { get; set; }
above lines link my tables to aspnet identity
on registration i entered data in one of my tables data entered successfully in identity and my tables but all identity tables regenerate with their original names with no data and other tables have data what i inserted.this problem is little annoying.if i manually delete these tables and next time register any employer these tables will regenerate again.
how to handle this.
Jithu ThomasPosted Jan 30, 2024, 5:38 AM
t looks like you are experiencing issues with Identity tables regenerating with their original names and no data. The problem might be related to the migrations and database initialization strategies you are using.
Here are a few steps you can take to handle this issue:
Check Migration History: Ensure that your migrations are being applied correctly. You can check the migration history table in your database. Look at the
__MigrationsHistorytable and make sure that the latest migration has been applied.Remove Existing Migrations: If you are still facing issues, you can try removing all existing migrations and then recreating them. Delete all migration files in your Migrations folder, except for the
Configuration.csfile. After that, you can run the following commands in the Package Manager Console:Seed Data in Configuration.cs: Ensure that you are seeding data in the
Configuration.csfile. This file is used for seeding data when the database is created or updated. In yourConfiguration.cs, you can override theSeedmethod to add initial data:Database Initialization Strategy: You are using the
MigrateDatabaseToLatestVersioninitializer, which should apply pending migrations on application startup. Make sure that this initialization strategy is working as expected. Alternatively, you can use other strategies likeDropCreateDatabaseIfModelChangesorCreateDatabaseIfNotExistsbased on your requirements.Example:
Debugging Migrations: You can use the
Update-Database -Verbosecommand in the Package Manager Console to get more detailed information about what migrations are being applied and if there are any errors.By following these steps, you should be able to troubleshoot and resolve the issue of Identity tables regenerating with their original names and no data. Remember to backup your database before making significant changes to avoid data loss.