gpt4 book ai didi

c# - 迁移在 Visual Studio CTP 6 vNext 项目中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:37 26 4
gpt4 key购买 nike

我创建了一个新项目 ASP.NET 5 Preview Starter Web。

按 Ctrl+F5 测试项目,工作正常。

在程序包管理器控制台中,我执行这些命令:

cd src
cd MyProject
k ef migration add initial

结果:

Using context 'ApplicationDbContext'.

现在我执行:

k ef migration apply

所以,我得到了这些错误:

Using context 'ApplicationDbContext'.
k : System.InvalidOperationException: A relational store has been configured without specifying either the DbConnection or connection string to use.
At line:1 char:1
+ k ef migration apply
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System.InvalidO... string to use.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

em Microsoft.Data.Entity.Relational.RelationalConnection..ctor(DbContextService`1 options, ILoggerFactory l
oggerFactory)
em Microsoft.Data.Entity.SqlServer.SqlServerConnection..ctor(DbContextService`1 options, ILoggerFactory loggerFactory)
--- Fim do rastreamento de pilha do local anterior onde a exce‡Æo foi gerada ---
em Microsoft.Framework.DependencyInjection.ServiceLookup.Service.ConstructorCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceLookup.Service.ConstructorCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceLookup.Service.ConstructorCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProvider.<>c__DisplayClass8_0.<RealizeService>b__0(ServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProvider.GetService(Type serviceType)
em Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
em Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
em Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredServiceChecked[TService](IServiceProvider serviceProvider)
em Microsoft.Data.Entity.Storage.DataStoreSource`2.get_StoreServices()
em Microsoft.Data.Entity.Storage.DataStoreSelector.SelectDataStore(ServiceProviderSource providerSource)
em Microsoft.Data.Entity.Infrastructure.DbContextServices.<>c__DisplayClass7_0.<Initialize>b__0()
em Microsoft.Data.Entity.Utilities.LazyRef`1.get_Value()
em Microsoft.Data.Entity.Infrastructure.DbContextServices.get_DataStoreServices()
em Microsoft.Data.Entity.Storage.DataStoreServices.GetStoreServices(IServiceProvider serviceProvider)
em Microsoft.Data.Entity.Storage.DataStoreServices.<>c__DisplayClass17_0.<get_DatabaseFactory>b__1()
em Microsoft.Data.Entity.Utilities.LazyRef`1.get_Value()
em Microsoft.Data.Entity.Infrastructure.DbContextService`1.get_Service()
em Microsoft.Data.Entity.DbContext.get_Database()
em WebApplication17.Models.ApplicationDbContext..ctor() na C:\users\paulo.larini\documents\visual studio 14\Projects\WebApplication17\src\WebApplication17\Models\IdentityModels.cs:linha 27

这应该有效,还是无效?

更新 - 1

应用 Aqua from mars 更改后,我收到以下错误:

k : System.Data.SqlClient.SqlException (0x80131904): ALTER TABLE DROP COLUMN failed because column 'NormalizedEmail-' does not exist in table 'AspNetUsers'.
At line:1 char:1
+ k ef migration apply
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System.Data.Sql... 'AspNetUsers'.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

em System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Act
ion`1 wrapCloseInAction)
em System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
em System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
em System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
em System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
em System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
em System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
em Microsoft.Data.Entity.Relational.SqlStatementExecutor.<>c__DisplayClass7_0.<ExecuteNonQuery>b__0()
em Microsoft.Data.Entity.Relational.SqlStatementExecutor.Execute(RelationalConnection connection, Func`1 action)
em Microsoft.Data.Entity.Relational.SqlStatementExecutor.ExecuteNonQuery(RelationalConnection connection, DbTransaction transaction, IEnumerable`1 sqlBatches)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.ExecuteStatementsWithinTransaction(IEnumerable`1 sqlStatements, RelationalConnection connection)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.ExecuteSqlBatches(IEnumerable`1 sqlBatches)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.ApplyMigration(Int32 index, Boolean simulate)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.<>c__DisplayClass33_0.<ApplyMigrations>b__5(Int32 i)
em System.Linq.Enumerable.<SelectManyIterator>d__8`2.MoveNext()
em System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.ApplyMigrations(Int32 targetMigrationIndex, Boolean simulate)
em Microsoft.Data.Entity.Relational.Migrations.Infrastructure.Migrator.ApplyMigrations()
em Microsoft.Data.Entity.Relational.Migrations.MigrationsEnabledDatabase.ApplyMigrations()
em WebApplication20.Models.ApplicationDbContext..ctor() na C:\users\paulo.larini\documents\visual studio 14\Projects\WebApplication20\src\WebApplication20\Models\IdentityModels.cs:linha 27
ClientConnectionId:00f13700-00da-40b8-af96-a330a029fdee
Error Number:4924,State:1,Class:16

最佳答案

仅当您在 OnConfiringMethod 中配置您的连接时它才有效

#if DEBUG  
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=localSQLdb;Trusted_Connection=True;MultipleActiveResultSets=true");
base.OnConfiguring(options);
}
#endif

更新响应 - 1

此版本 (CTP 6) 中生成的代码存在问题
要修复它,请像这样更新迁移代码:
迁移\DATE_initial.cd

    public override void Up(MigrationBuilder migrationBuilder)
{

....

migrationBuilder.DropColumn("AspNetUsers", "NormalizedEmail"); \\ remove the -

....

migrationBuilder.CreateTable("AspNetRoles",
c => new
{
Id = c.String(false), \\ set Id not nullable
Name = c.String()
})
.PrimaryKey("PK_AspNetRoles", t => t.Id);

....

migrationBuilder.CreateTable("AspNetUsers",
c => new
{
Id = c.String(false), \\ set Id not nullable
AccessFailedCount = c.Int(nullable: false),
....

关于c# - 迁移在 Visual Studio CTP 6 vNext 项目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com