I would like to know why and how to deal with the migration exception in EntityFramework 6.3

Asked 1 years ago, Updated 1 years ago, 101 views

Environment:
 VisualStudio 2017
 .NetFramework 4.6.1
 SQLite
 EntityFramework 6.3

The following exceptions occur while Migtaion interprets the DB Model created with code first in EntityFramework 6.3:
I looked it up and found that I was referring to __MigrationHistory and EdmMetadata.__MigrationHistory and EdmMetadata are not tables that I created myself.This exception is also printed when there is no table definition using DBSet.
The workaround for all sites was EntityFramework 6.2 or lower, but when I tried setting Database.SetInitializer null in the DbContext constructor, the exception never disappeared.
I would like to know how to make no exceptions in EntityFramework 6.3.
V Even if the following exceptions appear in the console output of VisualStudio, the application will still work as expected (it won't drop).

VisualStudio Console Output

Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException'
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException'
SQLite error (1): no such table: __MigrationHistory in "SELECT" 
GroupBy1.[A1]AS[C1]
FROM (SELECT) 
    Count([Filter1].[A1])AS[A1]
    FROM (SELECT) 
        1 AS [A1]
        FROM [__MigrationHistory] AS [Extent1]
        WHERE [Extent1]
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
SQLite error (1): no such table: __MigrationHistory in "SELECT" 
GroupBy1.[A1]AS[C1]
FROM (SELECT) 
    Count ([Extent 1].[A1]) AS[A1]
    FROM (SELECT) 
        1 AS [A1]
        FROM [__MigrationHistory] AS [Extent1]
    AS [Extent1]
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
SQLite trace: IServiceProvider.GetService for type "System.Data.Entity.Core.Common.DbProviderServices" (success).
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException'
SQLite error (1): no such table: __MigrationHistory in "SELECT" 
GroupBy1.[A1]AS[C1]
FROM (SELECT) 
    Count([Filter1].[A1])AS[A1]
    FROM (SELECT) 
        1 AS [A1]
        FROM [__MigrationHistory] AS [Extent1]
        WHERE [Extent1]
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
SQLite error (1): no such table: __MigrationHistory in "SELECT" 
GroupBy1.[A1]AS[C1]
FROM (SELECT) 
    Count ([Extent 1].[A1]) AS[A1]
    FROM (SELECT) 
        1 AS [A1]
        FROM [__MigrationHistory] AS [Extent1]
    AS [Extent1]
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
'BaseApp.exe' (CLR v4.0.30319: BaseApp.exe): 'EntityFrameworkDynamicProxies-EntityFramework' loaded.
SQLite error (1): no such table: EdmMetadata in "SELECT" 
[Extent 1].[Id] AS [Id], 
[Extent 1]. [ModelHash] AS [ModelHash]
FROM [EdmMetadata] AS [Extent1]
ORDER BY [Extent 1].[Id] DESC LIMIT 1" 
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.SQLite.SQLiteException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException'
Exception thrown: 'System.NotSupportedException' (in EntityFramework.dll)

Reference Page

c# sqlite entity-framework exception

2022-09-30 15:33

1 Answers

Since the error message says "no such table:__MigrationHistory", the first thing you need to do is check the configuration of the data veil (such as what name table is there).

As long as you are trying to browse to a table that does not exist, the exception "There is no such table!" continues.
Create the table you want, or rename the table you want to browse (if you have the wrong name for the table you are trying to browse).

That's all I can say when the question doesn't say what kind of program it is.


2022-09-30 15:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.