question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sync fails with duplicate key constraint failue

See original GitHub issue

Syncing from Sqlite to MySQL. First sync syncs to from the server to the client. Subsequent sync (to sync lo local change to the remote) fails with:

[InternalApplyThenGetChangesAsync]..[InternalApplyThenGetChangesAsync]..[InternalSaveScopeInfoClientAsync]..Duplicate entry '3ea49ef3-02c8-4cd0-af39-7acffab1338f-v1-YRV8q709t1f3m4tvB/5mP...' for key 'PRIMARY' (Dotmim.Sync.SyncException)
   at Dotmim.Sync.RemoteOrchestrator.InternalApplyThenGetChangesAsync(ScopeInfoClient cScopeInfoClient, ScopeInfo cScopeInfo, SyncContext context, ClientSyncChanges clientChanges, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress`1 progress)
   at Dotmim.Sync.SyncAgent.SynchronizeAsync(String scopeName, SyncSetup setup, SyncType syncType, SyncParameters parameters, CancellationToken cancellationToken, IProgress`1 progress)
   at Dotmim.Sync.SyncAgent.SynchronizeAsync(String scopeName, SyncSetup setup, SyncType syncType, SyncParameters parameters, CancellationToken cancellationToken, IProgress`1 progress)
[...]

It does appear before this that the client change is synced to the server, but something is going wrong here. This is with a minimal stock sync setup:

public class Foo
{
    public MariaDBSyncProvider ServerProvider { get; set; }
    public SqliteSyncProvider ClientProvider { get; set; }
    public SyncSetup Setup { get; set; }
    public SyncAgent Agent { get; set; }

    public Foo()
    {       
        ServerProvider = new MariaDBSyncProvider("Data Source=localhost,3306;Initial Catalog=project;User ID=user;Password=password");
        var path = ""; // redacted for simplicity
        ClientProvider = new SqliteSyncProvider(path);

        Setup = new SyncSetup("Table1", "Table2");

        Agent = new SyncAgent(ClientProvider, ServerProvider);
    }
    public async Task onEvent()
    {
        // Persist local changes...

        //...

        // Sync to remote...
        var result = await Agent.SynchronizeAsync("v1", Setup, SyncType.ReinitializeWithUpload);
        Console.WriteLine(result);
    }
}

Using:

      <PackageReference Include="Dotmim.Sync.MariaDB" Version="0.9.8" />
      <PackageReference Include="Dotmim.Sync.Sqlite" Version="0.9.8" />

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mimetiscommented, Apr 14, 2023

next version will be publish early next month I think

1reaction
Craigecommented, Feb 10, 2023

Let me put together a quick console app with a schema demonstrating the failure and I’ll get back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capsule sync fails with "duplicate key value violates ...
Issue. Getting following error when synchronizing Capsule. Raw. duplicate key value violates unique constraint ...
Read more >
Repo sync failed with: duplicate key value violates unique ...
Syncing AlmaLinux 8 Base repository fails with: duplicate key value violates unique constraint “rpm_updatecollection_name_update_record_id_6ef33bed_uniq”.
Read more >
postgresql duplicate key violates unique constraint
The "duplicate key" error is telling you that the work was not done because it would produce a duplicate key, not that it...
Read more >
Full Active Directory sync fails with constraint violation error
Active Directory full sync fails with duplicate key error. Steps to Reproduce. Use MS AD directory; Incremental synchronization disabled (enable ...
Read more >
Error when syncing channels in SUSE Manager 4.2
Error when syncing channels in SUSE Manager 4.2: duplicate key value violates unique constraint "rhn_channelcomps_cid_ctype_uq".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found