Ich verwende EF Core 2.0 und Postgres 9.6. Immer, wenn ich Daten einfügen erhalte ich die FehlerPostgresException: 23505: doppelte Schlüsselwert verstößt gegen eindeutige Einschränkung "PK_country"
PostgresException: 23505: doppelte Schlüsselwert verletzt einzigartige Einschränkung "PK_country"
Durch Tracing es wie EF sieht AutoInciment Spalte
My Model tut zu erzeugen
public partial class Country
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CountryId { get; set; }
[Display(Name="Country Name")]
public string CountryName { get; set; }
}
My-Controller
if (ModelState.IsValid)
{
_context.Add(country);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
Exception
> PostgresException: 23505: duplicate key value violates unique > constraint "PK_country" > > Npgsql.NpgsqlConnector+<DoReadMessage>d__148.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult() > Npgsql.NpgsqlConnector+<ReadMessage>d__147.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > Npgsql.NpgsqlConnector+<ReadMessage>d__147.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult() > Npgsql.NpgsqlDataReader+<NextResult>d__32.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > Npgsql.NpgsqlDataReader+<<NextResultAsync>b__31_0>d.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > Npgsql.NpgsqlCommand+<Execute>d__71.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult() > Npgsql.NpgsqlCommand+<ExecuteDbDataReader>d__92.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult() > Npgsql.NpgsqlCommand+<>c__DisplayClass90_0+<<ExecuteDbDataReaderAsync>b__0>d.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand+<ExecuteAsync>d__17.MoveNext() > System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() > System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task > task) > System.Runtime.CompilerServices.TaskAwaiter.GetResult() > Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch+<ExecuteAsync>d__32.MoveNext()
Was könnte das Problem sein?
Bitte aktualisieren Sie den Post und die Tags. ASP.NET CORE2 ist irrelevant, EF ** Core **, Version und verwendeter Postgres-Provider. –
Ok Ich udated die Post – Navigator
Danke. Siehe [Serial (Autoinkrement) -Spalten] (http://www.npgsql.org/efcore/value-generation.html#serial-autoincrement-columns) und wenn das in [Aktualisieren von 1.0.x] beschriebene Problem (http://www.npgsql.org/efcore/migration/1.1.html#upgrading-from-10x) gilt für Ihr Szenario. –