dotnet / dotnet/efcore

Warn when seeding with a 0 key

Open
#27,871 1 comment 0 reactions 0 assignees View on GitHub
area-migrations-seeding customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

> The seed entity for entity type 'T' cannot be added because a non-zero value is required for property 'Id'. Consider providing a negative value to avoid collisions with non-seed data.

Please consider removing this restriction. My identity starts at 1. If an Id of 0 is requested, I know it is not a valid request and would like it to point to a seeded "bad data" value in my database. I would like to use 0 as a seeded Id for the "bad data" since that is the default value for an integer.

Since it is still perfectly acceptable to use positive values when seeding (potentially causing collisions), having a restriction on using zero doesn't make much sense. If there is a good reason for this, please provide some information I can read about it.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: fc418ab9-0592-f610-e751-40cb501220da
* Version Independent ID: 822e8923-2647-f573-0c74-66af903776d8
* Content: [Data Seeding - EF Core](https://docs.microsoft.com/en-us/ef/core/modeling/data-seeding)
* Content Source: [entity-framework/core/modeling/data-seeding.md](https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/data-seeding.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @AndriySvyryd
* Microsoft Alias: **avickers**

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.