【发布时间】:2020-08-18 12:45:26
【问题描述】:
我有一个与另一个 IdentityServer4 一起运行的 asp.net mvc 项目(包括 Identity Core 支持的快速入门),但我无法更新数据库,也无法为其播种。我正在使用 Core。
我关注了this tuto
首先,我无法更新 de DB,我收到了这个错误:
System.InvalidOperationException:更改 IDENTITY 属性 列,需要删除并重新创建该列。在 Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(AlterColumnOperation 操作、IModel 模型、MigrationCommandListBuilder 构建器)在 Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.c.<.cctor>b__71_4(MigrationsSqlGenerator g, MigrationOperation o, IModel m, MigrationCommandListBuilder b)
在 Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation 操作、IModel 模型、MigrationCommandListBuilder 构建器)在 Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(MigrationOperation 操作、IModel 模型、MigrationCommandListBuilder 构建器)在 Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList1 operations, IModel model) at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(IReadOnlyList1 操作,IModel 模型)在 Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(迁移 迁移)在 Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.c__DisplayClass15_2.b__2() 在 Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(字符串 目标迁移)在 Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(字符串 targetMigration,字符串 contextType)在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(字符串 targetMigration,字符串 contextType)在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.<.ctor>b__0() 在 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(操作 action) 要更改列的 IDENTITY 属性,该列需要 被删除并重新创建。
第二件事,我意识到startup.cs中的seed方法不起作用,seed返回一个false
试试 { var 种子 = args.Contains("/seed"); 如果(种子) { args = args.Except(new[] { "/seed" }).ToArray(); }
var host = CreateHostBuilder(args).Build(); if (seed) { Log.Information("Seeding database..."); var config = host.Services.GetRequiredService<IConfiguration>(); var connectionString = config.GetConnectionString("DefaultConnection"); SeedData.EnsureSeedData(connectionString); Log.Information("Done seeding database."); return 0; }
我不知道是否有人已经使用过该教程,但是非常感谢您的帮助:p Thx
【问题讨论】:
标签: c# asp.net-identity identityserver4