Lutando
Lutando

Reputation: 5010

Entity Framework 7 (Beta7) migration script generating invalid table name

When I generate a migration script using the ef 7 powershell commands

dnx ef migrations add Initial -c MyDbContext
dnx ef migrations script -c MyDbContext

I get a script that has, in the first few lines, the following;

Using context 'MyDbContext'.
Generating up script for migration '20151001104737_Initial'.
IF OBJECT_ID(N'__MigrationHistory') IS NULL
    CREATE TABLE [__MigrationHistory] (
        [MigrationId] nvarchar(150) NOT NULL,
        [ProductVersion] nvarchar(32) NOT NULL,
        CONSTRAINT [PK_HistoryRow] PRIMARY KEY ([MigrationId])
    );

GO

When I run the script on my SQL Databases to apply my migration I get the error

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'MyDbContext'. Msg 208, Level 16, State 1, Line 98 Invalid object name '__MigrationHistory'.

I have run this script on SQL Server database versions 11, 12 & 13 and I get the same error throughout. It is clearly complaining that the table name __MigrationHistory isnt a valid table name it seems.

Upvotes: 2

Views: 466

Answers (1)

Lutando
Lutando

Reputation: 5010

Figured out the problem

I was piping the ef command into a file and the first two lines are just descriptions of what is going on while the command is running

so if you are doing something like

dnx ef migrations script -c MyDbContext > myscript.sql 

then make sure to remove the first two lines before running the script

Upvotes: 2

Related Questions