This is similar to the fact that you may have used the database to test your migrations when making changes. The EF5 migration history table has the following structure:
CREATE TABLE [dbo].[__MigrationHistory]( [MigrationId] [nvarchar](255) NOT NULL, [Model] [varbinary](max) NOT NULL, [ProductVersion] [nvarchar](32) NOT NULL CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY CLUSTERED ( [MigrationId] ASC ) )
When I upgraded the project from EF5 to EF6, I added an explicit migration for this. If you use decimal fields, then migration will be necessary anyway, since it recreates them using explicit precision anyway. When you start this first migration under EF6, it recreates the migration history table using a new structure that looks like ...
CREATE TABLE [dbo].[__MigrationHistory2] ( [MigrationId] [nvarchar](150) NOT NULL, [ContextKey] [nvarchar](300) NOT NULL, [Model] [varbinary](max) NOT NULL, [ProductVersion] [nvarchar](32) NOT NULL, CONSTRAINT [PK_dbo.__MigrationHistory2] PRIMARY KEY ([MigrationId], [ContextKey]) )
You can see that this table contains a ContextKey field that is not null. Due to the error you are getting, I would suggest that you are trying to migrate using EF5 in an EF6 format database.
If you want to return your database to EF5 format to migrate from EF5, just release the ContextKey field and recreate the primary key:
ALTER TABLE dbo.__MigrationHistory DROP CONSTRAINT [PK_dbo.__MigrationHistory2] ALTER TABLE dbo.__MigrationHistory DROP COLUMN ContextKey ALTER TABLE dbo.__MigrationHistory ADD CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY (MigrationId)
source share