Skip to content

Commit

Permalink
Fix for 17509. Do not allow migration to have same name as context. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lajones committed Mar 3, 2020
1 parent e36b86f commit 3197d54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/EFCore.Design/Design/Internal/MigrationsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public virtual MigrationFiles AddMigration(
var subNamespace = SubnamespaceFromOutputPath(outputDir);

using var context = _contextOperations.CreateContext(contextType);
var contextClassName = context.GetType().Name;
if (string.Equals(name, contextClassName, StringComparison.Ordinal))
{
throw new OperationException(
DesignStrings.ConflictingContextAndMigrationName(name));
}

var services = _servicesBuilder.Build(context);
EnsureServices(services);
EnsureMigrationsAssembly(services);
Expand Down
12 changes: 10 additions & 2 deletions src/EFCore.Design/Properties/DesignStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,7 @@ Change your target project to the migrations project by using the Package Manage
<data name="UnhandledEnumValue" xml:space="preserve">
<value>Unhandled enum value '{enumValue}'.</value>
</data>
<data name="ConflictingContextAndMigrationName" xml:space="preserve">
<value>The name you have chosen for the migration, '{name}', is the same as the context class name. Please choose a different name for your migration. Might we suggest 'InitialCreate' for your first migration?</value>
</data>
</root>

0 comments on commit 3197d54

Please sign in to comment.