Can I move the __MigrationHistory System table to a new server?

We recently moved our database to a new server. However, at that time we did not allow Code First migrations to create the database. We used another tool to transfer tables and data. At this time, the __MigrationHistory table was not moved. __MigrationHistory is the system table in our source database.

I cannot find a way to import or export the __MigrationHistory table so that we can allow future migrations.

The only other thought we had was that the application recreate the database and transfer the copied data to the new version of the database. The only problem is that we have millions of records to move around, and this is a pretty long process.

+4
source share
1 answer

I use the following script to move the EF MigrationHistory table from system tables to user tables (database tree structure):

SELECT * INTO [dbo].[TempMigrationHistory] FROM [dbo].[__MigrationHistory];

DROP TABLE [dbo].[__MigrationHistory];

EXEC sp_rename 'TempMigrationHistory', '__MigrationHistory';

Thus, I can export the table by selecting the standard script / export option under SSMS.

(A full description of the handling of this problem is here )

+5
source

All Articles