There is already an object in the database with the name "__MigrationHistory"

When I tried to execute SQLQuery (generated Update-Database -Verbose -f -Scriptlocally in Visual Studio) in a remote database, I saw the following error returned by SQL Server Management Studio:

Msg 2714, Level 16, State 6, Line 1

There is already an object in the database named __MigrationHistory.

How to solve this?

+4
source share
6 answers

__MigrationHistory - , EF , / . EF . // . , . EF script ​​, . /, , EF , .

+3

. , dbo?

, EF, , , __MigrationHistory.

, Dummy __MigrationHistory dbo, EF6 " "

CREATE TABLE [dbo].[__MigrationHistory] ( [MigrationId] [nvarchar](150) NOT NULL, [ContextKey] [nvarchar](300) NOT NULL, [Model] [varbinary](max) NOT NULL, [ProductVersion] [nvarchar](32) NOT NULL, CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY ([MigrationId], [ContextKey]) )

, , dbo . , .

+3

, " ", __MigrationHistory.

POCO . , .

+2

, - , , __MigrationHistory, script

update-database -script -SourceMigration $InitialDatabase

script , , . , script, - __MigrationHistory , .

+1

. add-migration MigrationName , , ,

0
source

Change the database name in the connection string in web.config, which was resolved after the changing database. This is a workaround that helps in development environments. Db has been recreated with new objects.

0
source

All Articles