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

Warn when using a newer version of dotnet ef with old runtime (command specific) #25153

Closed
nicolas-2008 opened this issue Jun 25, 2021 · 6 comments · Fixed by #26127
Closed
Assignees
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@nicolas-2008
Copy link

nicolas-2008 commented Jun 25, 2021

I'm looking for the possibility to get the list of unapplied migrations in Ef Core.
I found the discussion about the same and it seems like it was implemented in Ef Core 5.0.
This however doesn't work for me.

Preconditions

  1. The latest version of the tool is installed:
    dotnet ef --version
    Entity Framework Core .NET Command-line Tools
    5.0.7

  2. There is a project with migrations and DbContextFactory class that implements IDesignTimeDbContextFactory<CoreContext> interface to build the DbContext. It is successfully picked up by the tool (dotnet ef database update and other commands that required db connection work without issues).

What I tried so far

  1. dotnet ef migrations list --json
    "applied" property is null for all migrations, however all of them are applied. (Operation fails in case if incorrect connection string passed to CoreContext from DbContextFactory).
    [
    {
    "id": "20210620081822_SomeMigration",
    "name": "SomeMigration",
    "safeName": "SomeMigration",
    "applied": null
    },
    {
    "id": "20210620083523_SomeOtherMigration",
    "name": "SomeOtherMigration",
    "safeName": "SomeOtherMigration",
    "applied": null
    }
    ]

  2. dotnet ef migrations list --no-connect --json
    Operation executed successfully (so option --no-connect which was added in scope of aforementioned PR does exist).
    Result is the same.

  3. dotnet ef migrations list --no-connect false --json
    Operation fails with the message:
    Unrecognized command or argument 'false'.

Am I doing something wrong or is it a bug?

@bricelam
Copy link
Contributor

Could you share a repro? If dotnet ef database update works, it should be able to show whether a migration has been applied.

@bricelam bricelam self-assigned this Jun 25, 2021
@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Jun 25, 2021
@nicolas-2008
Copy link
Author

My fault. I found that it happens only if project uses older version of ef core.
Though, having "applied: null" in the output and no warnings about version mismatch is a bit confusing.

@bricelam
Copy link
Contributor

bricelam commented Jun 28, 2021

no warnings about version mismatch

It didn't show the following warning?

The Entity Framework tools version '3.1' is older than that of the runtime '5.0'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.

Can you share a repro?

@bricelam bricelam reopened this Jun 28, 2021
@bricelam
Copy link
Contributor

Oh wait, that warning goes the other way. You were using newer tools with an older runtime, right?

We should consider showing a warning for specific features that might not work. Another example would be the new compiled models command.

@bricelam bricelam removed this from the 6.0.0 milestone Jun 28, 2021
@nicolas-2008
Copy link
Author

Hi @bricelam,
I was using dotnet ef tool 5.0.7 with a project that targets net5.0 and references "Microsoft.EntityFrameworkCore" 2.2.6, "Microsoft.EntityFrameworkCore.Design" 2.2.6.

@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Jun 29, 2021
@AndriySvyryd AndriySvyryd changed the title How to use dotnet ef migrations list to see the status Ef Core migrations? Warn when using a newer version of dotnet ef with old runtime (command specific) Sep 15, 2021
@bricelam
Copy link
Contributor

Added an error for dotnet ef migrations bundle here:

if (new SemanticVersionComparer().Compare(EFCoreVersion, "6.0.0") < 0)
{
throw new CommandException(Resources.VersionRequired("6.0.0"));
}

We should add similar code to warn for dotnet ef migrations list and error for dotnet ef dbcontext optimize.

bricelam added a commit to bricelam/efcore that referenced this issue Sep 21, 2021
@bricelam bricelam added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed poachable labels Sep 21, 2021
bricelam added a commit to bricelam/efcore that referenced this issue Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants