【问题标题】:Migration does not work in Visual Studio CTP 6 vNext project迁移在 Visual Studio CTP 6 vNext 项目中不起作用
【发布时间】:2015-03-25 10:44:51
【问题描述】:

我创建了一个新项目 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 后,我收到以下错误:

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

【问题讨论】:

    标签: c# asp.net-mvc entity-framework asp.net-core


    【解决方案1】:

    只有在 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)
    要修复它,请像这样更新迁移代码:
    Migration\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),
     ....
    

    【讨论】:

    • 执行此操作后,重新运行应用命令并在我的更新 1 中得到错误。
    • 我从不测试删除列,也许有问题。你用的kre是什么?
    • K 版本管理器 - 内部版本 10319
    • 你到底要我做什么?
    • 您使用的运行时是什么?执行kvm list
    【解决方案2】:

    CTP 6 在这一点上有太多的错误。

    我会等待下一个版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 2022-07-31
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多