Azure App Services (Mobile App) Violation of PRIMARY KEY constraint Azure App Services (Mobile App) Violation of PRIMARY KEY constraint sqlite sqlite

Azure App Services (Mobile App) Violation of PRIMARY KEY constraint


There are a lot of possible things that could be going wrong: maybe your client is actually doing another insert instead of an update, which is why you'd get a 409 conflict exception. Or, less likely, the insert succeeded but the response was lost, so the client will retry the insert, and will get the exception.

Or, it could be that the problem is the relationship between the tables. To debug this, first you should log your outgoing requests so you can see what's going on. If your client is sending inserts instead of updates, you'll see that in your log. See Log outgoing requests in managed client (Xamarin, Windows).

You can then attach a debugger to either your remote service or the one running locally to see why the Entity Framework validation error is occurring.

Btw, if you're doing offline sync, you should also add conflict handling code. Here's a sample that handles 409 (for the case when Insert suceeds and the response is lost) and 412 precondition failed (when two clients try to update the same data): https://github.com/lindydonna/xamarin-forms-offline-sync/blob/master/XamarinFormsOffline/SyncHandler.cs#L23.


It seems that Azure App Services (Mobile Apps) is unable to handle foreign keys when using SQLite as an intermediary at the current moment. As such the only way to do it is to handle the tables as 2 separate entities on the client site (you can choose to keep the foreign key on the service end, however this will cause problems trying to query the data with the foreign key).