Skip to content

Migration name filter #23222

Closed

Description

@lugospod

EF Core uses a class Migration, and if you add a new migration with name "Migration" it will break the build.

dotnet ef migrations add Migration

results with Circular base class dependency involving 'Migration' and 'Migration'

I recommend that "migrations add" adds a validation for this...

Include stack traces

Migrations/20201106105308_Migration.cs(6,26): error CS0146: Circular base class dependency involving 'Migration' and 'Migration' [/opt/app/src/src/NM.DAL/NM.DAL.csproj]
Migrations/20201106105308_Migration.cs(8,33): error CS0115: 'Migration.Up(MigrationBuilder)': no suitable method found to override [/opt/app/src/src/NM.DAL/NM.DAL.csproj]
Migrations/20201106105308_Migration.cs(167,33): error CS0115: 'Migration.Down(MigrationBuilder)': no suitable method found to override [/opt/app/src/src/NM.DAL/NM.DAL.csproj]
Migrations/20201106105308_Migration.Designer.cs(16,33): error CS0115: 'Migration.BuildTargetModel(ModelBuilder)': no suitable method found to override [/opt/app/src/src/NM.DAL/NM.DAL.csproj]

Include provider and version information

EF Core version: 3.1.9
Database provider: Postgresql
Target framework: NET 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.7.7

Activity

  1. ajcvickers commented on Nov 7, 2020

    @ajcvickers
    Contributor

    Note from triage: we should add this and other similar conflicts to the check we already have. But low priority.

  2. added
    good first issue
    on Nov 7, 2020
  3. added this to the Backlog milestone on Nov 7, 2020
  4. wreuel commented on Mar 28, 2021

    @wreuel

    How could I help with that?

  5. ZephArvanitis commented on Apr 17, 2021

    @ZephArvanitis

    Would this line/file be the right place to add this check?

    protected override void Validate()
    {
    base.Validate();
    if (string.IsNullOrEmpty(_name!.Value))
    {
    throw new CommandException(Resources.MissingArgument(_name.Name));
    }
    }

  6. KevRitchie commented on Oct 13, 2021

    @KevRitchie
    Contributor

    Hi @ajcvickers, is this still up for grabs?

  7. ajcvickers commented on Oct 13, 2021

    @ajcvickers
    Contributor
  8. KevRitchie commented on Oct 14, 2021

    @KevRitchie
    Contributor

    Thanks @ajcvickers.

    In summary, the changes I'm proposing are:

    • Add a check during the Validate method of MigrationsAddCommand to throw a CommandException when someone tries to call their migration "migration".
    • Add a new resource "CircularBaseClassDependency" to notify the user that "You cannot add a migration with the name 'Migration'".

    Does that look OK?

    I'm also trying to track down the tests for the MigrationsAddCommand, but can't find any. Could you point me in the right direction?

    Thanks 😄

  9. ajcvickers commented on Oct 14, 2021

    @ajcvickers
    Contributor

    @bricelam Can you comment on the proposed design here?

  10. KevRitchie commented on Oct 18, 2021

    @KevRitchie
    Contributor

    @ajcvickers @bricelam - I have a version ready to go 😄 Is there anything else you think I need to add/consider (based on the above implementation)?

  11. bricelam commented on Oct 18, 2021

    @bricelam
    Contributor

    LGTM Feel free to send a PR

  12. added a commit that references this issue on May 19, 2022
    49328ec
  13. modified the milestones: Backlog, 7.0.0 on May 19, 2022
  14. modified the milestones: 7.0.0, on May 25, 2022
  15. modified the milestones: , 7.0.0 on Nov 5, 2022
  16. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-migrationscommunity-contributioncustomer-reportedgood first issue

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions