Problem while "dotnet ef migrations add Init"

When I'm trying to add data base migration i get error "The seed entity for entity type 'Contract' cannot be added because a non-zero value is required for property 'ContractId'. Consider providing a negative value to avoid collisions with non-seed data."
table (look screenshot)
insert :
   new Contract
            {
                CustomerId = 1, SoftwareId = 1, Version = "1.0", StartDate = new DateTime(2024, 1, 1),
                EndDate = new DateTime(2024, 1, 10), Price = 1000.00m, DiscountId = 1, SupportYears = 1,
                IsSigned = false
            },

table has autoincrementation:
modelBuilder.Entity<Contract>()
            .Property(c => c.ContractId)
            .ValueGeneratedOnAdd();


table code:
using System.ComponentModel.DataAnnotations.Schema;

namespace Company_APBD.Models;

public class Contract
{
    public int ContractId { get; set; }
    public int CustomerId { get; set; }
    public int SoftwareId { get; set; }
    public string Version { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public decimal Price { get; set; }
    public int DiscountId { get; set; }
    public int SupportYears { get; set; }
    public bool IsSigned { get; set; }

   
}
image.png
image.png
Was this page helpful?