我需要调试PM> add-migration <name>
,该怎么做?
背景: 它引发以下错误。我想找到谁的原因
System.ArgumentNullException: Value cannot be null.
Parameter name: derivedType
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.EntityTypeExtensions.IsAssignableFrom(IEntityType entityType, IEntityType derivedType)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c__DisplayClass55_1.<StopTracking>b__0(INavigation n)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StopTracking(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Nullable`1 forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDataOperations()+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
答案 0 :(得分:0)
连接字符串为null
时最常见的错误。
这不是您想要的,但是无论如何,它可以为您提供帮助。尝试记录错误或调试信息:
public class Startup
{
private ILogger<Startup> Logger { get; }
public Startup(ILogger<Startup> logger)
{
Logger = logger;
}
public void ConfigureServices(IServiceCollection services)
{
Logger.LogError("test"); <========= It will output messages
string connection = null;
services.AddDbContext<TestContext>(builder => builder.UseSqlServer(connection));
...
}
...
}