I have added Microsoft.AspNetCore.Identity.EntityFrameworkCore
via nuget.
StartUp
public void ConfigureServices(IServiceCollection services)
{
//Add PostgreSQL support
services.AddEntityFrameworkNpgsql()
.AddDbContext<StoreDbContext>(options =>
options.UseNpgsql(Configuration["Data:StoreDbContext:ConnectionString"]));
// Add framework services.
services.AddMvc();
services.AddIdentity<PostgreApp.Models.User, IdentityRole>()
.AddEntityFrameworkStores<StoreDbContext>()
.AddDefaultTokenProviders();
// Add our PostgreSQL Repository
services.AddTransient<IStoreRepository, StoreRepository>();
}
In StartUp' Configure I have added following:
app.UseIdentity();
This is my code:
public class StoreDbContext: IdentityDbContext<User>
{
public StoreDbContext(DbContextOptions<StoreDbContext> options) : base(options)
{
}
public DbSet<Store> Stores { get; set; }
public DbSet<Company> Companies { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<JobPost> JobPosts { get; set; }
public DbSet<Candidate> Candidates { get; set; }
public DbSet<CandidateCV> CandidateCVs { get; set; }
public DbSet<Criterion> Criteria { get; set; }
public DbSet<AssessmentStage> AssessmentStages { get; set; }
public DbSet<AssessmentCriterion> AssessmentCriteria { get; set; }
public DbSet<JobpostCv> JobpostCvs { get; set; }
}
Then I am getting this:
System.InvalidOperationException: Column Id of type text has ValueGenerated.OnAdd but no default value is defined at Microsoft.EntityFrameworkCore.Migrations.NpgsqlMigrationsSqlGenerator.ColumnDefinition(String schema, String table, String name, Type clrType, String type, Nullable
1 unicode, Nullable
1 maxLength, Boolean rowVersion, Boolean nullable, Object default Value, String defaultValueSql, String computedColumnSql, IAnnotatable annotatable, IModel model, MigrationCommandListBuilder builder) at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.ColumnDefinition(AddColumnOperation operation, IModel model, MigrationCommandListBuilder builder) at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder, Boolean terminate) at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder) at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder) at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model) at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration) at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.b__0()at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[]
args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) Column Id of type text has ValueGenerated.OnAdd but no default value is defined
How do I solve this ?