2016-09-09 1 views
1

여기 내 Dataseeder 클래스의 :오류 db.Database.Migrate()를 실행하는 동안 : 잘못된 구문 키워드를 근처에 'NOT'

using Microsoft.AspNetCore.Builder; 
using Microsoft.AspNetCore.Identity; 
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 
using Microsoft.EntityFrameworkCore; 
using Microsoft.Extensions.DependencyInjection; 
using StackStore.Data; 
using System.Collections.Generic; 
using System.Linq; 

namespace StackStore.Models 
{ 
    // http://stackoverflow.25lm.com/questions/34536021/seed-initial-data-in-entity-framework-7-rc-1-and-asp-net-mvc-6 
    public static class DataSeeder // EntityFramework 7.0 DataSeeder 
    { 
     // TODO: Move this code when seed data is implemented in EF 7 

     /// <summary> 
     /// This is a workaround for missing seed data functionality in EF 7.0-rc1 
     /// More info: https://github.com/aspnet/EntityFramework/issues/629 
     /// </summary> 
     /// <param name="app"> 
     /// An instance that provides the mechanisms to get instance of the database context. 
     /// </param> 
     public static async void SeedData(this IApplicationBuilder app) 
     { 
      var db = app.ApplicationServices.GetService<ApplicationDbContext>(); 

      //Caution: Clear all the tables in the database first. 
      db.Database.Migrate(); 


      db.SaveChanges(); 
     } 
    } 
} 

기본적으로 오류가 db.Database.Migrate (에서 히트)과 던졌습니다 나에 대해 전혀 몰랐던이 덩어리. 나는 오류의 출처를 찾기 위해 최선을 다했지만 아무 소용이 없었습니다. 마이그레이션 방법의 정의를 확인하려고 시도합니다. 내가 엔티티 관계 구문 오류가

System.Data.SqlClient.SqlException was unhandled by user code 
    Class=15 
    HResult=-2146232060 
    LineNumber=7 
    Message=Incorrect syntax near the keyword 'NOT'. 
    Number=156 
    Procedure="" 
    Server=NIXHOLAS\SQLEXPRESS 
    Source=Core .Net SqlClient Data Provider 
    State=1 
    StackTrace: 
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 
     at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) 
     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) 
     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean openConnection, Boolean closeConnection) 
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues, Boolean manageConnection) 
     at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection) 
     at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) 
     at StackStore.Models.DataSeeder.<SeedData>d__0.MoveNext() in C:\Users\nixho\StackStore\src\StackStore\Models\DataSeeder.cs:line 36 
    InnerException: 


    Microsoft.EntityFrameworkCore.DbUpdateException was unhandled by user code 
    HResult=-2146233088 
    Message=An error occurred while updating the entries. See the inner exception for details. 
    Source=Microsoft.EntityFrameworkCore.Relational 
    StackTrace: 
     at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.<ExecuteAsync>d__1.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__47.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__45.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.EntityFrameworkCore.DbContext.<SaveChangesAsync>d__30.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore`5.<SaveChanges>d__14.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore`5.<CreateAsync>d__15.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at Microsoft.AspNetCore.Identity.RoleManager`1.<CreateAsync>d__30.MoveNext() 
    --- End of stack trace from previous location where exception was thrown --- 
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 
     at StackStore.Models.DataSeeder.<SeedData>d__0.MoveNext() in C:\Users\nixho\StackStore\src\StackStore\Models\DataSeeder.cs:line 44 
    InnerException: 
     Class=16 
     HResult=-2146232060 
     LineNumber=2 
     Message=Invalid object name 'AspNetRoles'. 
     Number=208 
     Procedure="" 
     Server=NIXHOLAS\SQLEXPRESS 
     Source=Core .Net SqlClient Data Provider 
     State=1 
     StackTrace: 
      at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__107_0(Task`1 result) 
      at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() 
      at System.Threading.Tasks.Task.Execute() 
     --- End of stack trace from previous location where exception was thrown --- 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
      at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.<ExecuteAsync>d__20.MoveNext() 
     --- End of stack trace from previous location where exception was thrown --- 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
      at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext() 
     InnerException: 
+0

MSDN에서 --->'데이터베이스 변경 사항 저장이 실패 할 때 DbContext에 의해 예외가 throw됩니다. DbUpdateException ---> 데이터베이스에 업데이트를 보내는 중 오류가 발생했습니다 .'. –

+0

'dotnet ef migrations script'를 실행하고 언급 된'NOT'이 어디에 있는지 알 수 있습니까? – bricelam

+0

또한 어떤 버전의 SQL Server를 사용하고 있습니까? (2005 년은 지원되지 않습니다.) – bricelam

답변

0

:

다음은 오류입니다. ApplicationDbContext에는 내가 해결하지 못한 몇 가지 관계 문제가 있습니다.

기본적으로 마이그레이션하기 전에 자신의 ApplicationDbContext를 확인하십시오.