dotnet / dotnet/efcore

Constraint names we generate by convention don't check for duplicates with explicitly generated constraint names

Open
#36,049 0 comments 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-model-building area-relational-mapping
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

E.g. migration test like:

```cs
await Test(
builder =>
{
builder.Entity("Entity").Property("Id");
builder.Entity("Entity").HasKey("Id").HasName("PK_AnotherEntity");
},
builder => { },
builder =>
{
builder.Entity("AnotherEntity").Property("Id");
},
model =>
{
});
```

We explicitly generate PK_AnotherEntity, then create new entity who's by convention PK constraint is named the same -

```
Microsoft.Data.SqlClient.SqlException : There is already an object named 'PK_AnotherEntity' in the database.
Could not create constraint or index. See previous errors.
```

Ideally we would check all constraint types - one could generate default constraint with a name that would clash with PK constraint, or vice versa - this still results in the same error

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.