Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL: Error 42P10 - there is no unique or exclusion constraint matching the ON CONFLIC #1023

Open
AnikeRU opened this issue Mar 7, 2023 · 2 comments

Comments

@AnikeRU
Copy link

AnikeRU commented Mar 7, 2023

Hello

To avoid this error in Postgres add unique index to the table PluralTranslation in LocalizationDbContext.cs:

builder.Entity().HasIndex(e => new { e.LocalizationRecordId, e.Index }, "IX_LOCRECID_INDEX").IsUnique();

Else this row will be generate error 42P10 :

localization DbContext.Plural Translations.UpsertRange(plural Translations).On(l => new { l.Localization RecordId, l.Index }).RunAsync();

@enkodellc
Copy link
Owner

Thanks, would you care to share it as a PR?

@AnikeRU
Copy link
Author

AnikeRU commented May 9, 2023

Yes, you can use this code in a blazorboilerplate project.
New content of the LocalizationDbContext.cs:

`
using BlazorBoilerplate.Infrastructure.Storage.DataModels;
using Microsoft.EntityFrameworkCore;

namespace BlazorBoilerplate.Storage
{
public class LocalizationDbContext : DbContext
{
public LocalizationDbContext(DbContextOptions options) : base(options)
{ }

    public DbSet<PluralFormRule> PluralFormRules { get; set; }

    public DbSet<PluralTranslation> PluralTranslations { get; set; }

    public DbSet<LocalizationRecord> LocalizationRecords { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<LocalizationRecord>().HasIndex(c => new { c.MsgId, c.Culture, c.ContextId }).IsUnique();
        builder.Entity<PluralTranslation>().HasIndex(e => new { e.LocalizationRecordId, e.Index }, "IX_LOCRECID_INDEX").IsUnique();
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants