This is a migrated thread and some comments may be shown as answers.

Create data again and again

1 Answer 35 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Calebe
Top achievements
Rank 1
Calebe asked on 06 Jan 2016, 12:54 PM

I have tried to create an row on Backend Service after I have created another. I do not intend to create multiple, but let the user create repeatedly. To do the the button on NativeScript/Everlive calls this function.

 But, after first time, Everlive shows this error: The operation results in a duplicate key for a unique index. code 107

exports.addMed = function(args) {
    disableButtons();
    med.isLoading = true;
    data.create(medidas.registros, function(data) {
        med.isLoading = false;
        enableButtons();
    }, function(data) {
        med.isLoading = false;
        enableButtons();
    });
};

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 08 Jan 2016, 12:50 PM

Hi Calebe,

The “duplicate key for a unique index” message with error code 107 is returned from the server when the request is trying to add an item with an Id while there is an item with the same Id in the database. This is due to the fact that the Id field must be unique. To solve this consider either:

1.       Do not enter an Id when creating the item(s). The Id will be populated automatically by the system.

2.       If you want to have your own custom ID for each item, make sure each one is unique.

Let me know if this helps.

Best regards,

Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Calebe
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or