Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script-Migration -idempotent creates script with errors #19740

Closed
sdpollack opened this issue Jan 29, 2020 · 5 comments
Closed

Script-Migration -idempotent creates script with errors #19740

sdpollack opened this issue Jan 29, 2020 · 5 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@sdpollack
Copy link

I'm trying to create an idempotent migration script (as I've done previously). The resulting script won't load due to errors.

Steps to reproduce

  1. At the VS Package Manager Console, issue command "Script-Migration -idempotent"
  2. Connect to a database running an earlier migration.
  3. run the script.

Loading the script in VS shows 3 errors. Running the script results in 5 errors.

sd5bgmh0.txt

Msg 156, Level 15, State 1, Line 792
Incorrect syntax near the keyword 'procedure'.
Msg 156, Level 15, State 1, Line 1255
Incorrect syntax near the keyword 'procedure'.
Msg 137, Level 15, State 2, Line 1268
Must declare the scalar variable "@unitid".
Msg 156, Level 15, State 1, Line 1306
Incorrect syntax near the keyword 'procedure'.
Msg 137, Level 15, State 2, Line 1324
Must declare the scalar variable "@parentUnitId".
Msg 102, Level 15, State 1, Line 1333
Incorrect syntax near ')'.

Further technical details

EF Core version: 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer 3.1.1
Target framework: .NET Core 3.1
Operating system: Windows 10 Enterprise 1909
IDE: (e.g. Visual Studio 2019 16.3) VS 16.4.2

@ajcvickers
Copy link
Member

Could be a dupe of #12911.
/cc @bricelam

@bricelam
Copy link
Contributor

Not exactly a dupe. CREATE PROCEDURE calls are tricky since they need to be the first statement in a batch. EF6 wraps them inside EXEC:

EXECUTE('
    CREATE PROCEDURE ...
')

@ajcvickers
Copy link
Member

Linked to docs: dotnet/EntityFramework.Docs#694

@bricelam
Copy link
Contributor

bricelam commented Feb 5, 2020

@sdpollack In case I was too subtle, you can work around this by changing your migration to use EXEC:

migrationBuilder.Sql(@"
    EXECUTE('
        CREATE PROCEDURE ...
    ')
");

@ajcvickers
Copy link
Member

Tracked by documentation and #245

@ajcvickers ajcvickers added closed-no-further-action The issue is closed and no further action is planned. and removed type-bug labels Feb 14, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants