The database applies ALL previous migrations when updating, and NOT just a new one

I am developing a website that currently has a production and test database. The production database is hosted externally, while the test database is hosted locally.

Whenever I make changes to my database, I apply the changes through migration. After adding a new migration, I ran the update-database command in my production and test database to synchronize them.

I applied migration only in my working database, however, when I want to apply migration to my test database, I see that it is trying to apply ALL previous migrations (and not just new ones):

Here is the result:

Application of explicit migration: [201603230047093_Initial, 201603232305269_AddedBlobNameToImage, 201603242121190_RemovedSourceFromRealestateDbTable, 201603311617077_AddedSourceUrlId, 201604012033331_AddedIndexProfileAndFacebookNotifications, 201604012233271_RemovedTenantIndexProfile, 201604042359214_AddRealestateFilter]. Explicit migration application: 201603230047093_Initial. System.Data.SqlClient.SqlException (0x80131904): the object already has an object with the name "Cities" of the database.

Obviously, this fails because the current state of the database is in the second last migration. However, I wonder why he is trying to apply ALL previous migrations?

( ) , :

201604012239054_InitialCreate 

( , InitialCreate ).

:

?

EDIT: COMMMAND script:

DECLARE @CurrentMigration [nvarchar](max)

IF object_id('[dbo].[__MigrationHistory]') IS NOT NULL
    SELECT @CurrentMigration =
        (SELECT TOP (1) 
        [Project1].[MigrationId] AS [MigrationId]
        FROM ( SELECT 
        [Extent1].[MigrationId] AS [MigrationId]
        FROM [dbo].[__MigrationHistory] AS [Extent1]
        WHERE [Extent1].[ContextKey] = N'Boligside.Migrations.Configuration'
        )  AS [Project1]
        ORDER BY [Project1].[MigrationId] DESC)

IF @CurrentMigration IS NULL
    SET @CurrentMigration = '0'

IF @CurrentMigration < '201603230047093_Initial'

( if )

( , , ): enter image description here

+4
1

, , , . :

1) __MigrationHistory :

UPDATE [dbo].[__MigrationHistory]
   SET [ContextKey] = ‘New_Namespace.Migrations.Configuration’
 WHERE [ContextKey] = ‘Old_Namespace.Migrations.Configuration’

2) . :

public Configuration()
{
    AutomaticMigrationsEnabled = false;
    this.ContextKey = "Old_Namespace.Migrations.Configuration";
}

, : https://msdn.microsoft.com/en-US/data/dn481501?f=255&MSPPError=-2147217396

. http://jameschambers.com/2014/02/changing-the-namespace-with-entity-framework-6-0-code-first-databases/

+4

All Articles