Devtoberfest Discussions
Join in the conversations with your fellow participants, on anything and everything to do with Devtoberfest!
cancel
Showing results for 
Search instead for 
Did you mean: 

SQLITE_CONSTRAINT: UNIQUE constraint failed error during CAP Tutorial Execution

mainak-aich
Participant
0 Kudos
970

Hi CAP Experts, I am working on the CAP Tutorial https://developers.sap.com/tutorials/cp-apm-nodejs-create-service.html#ad94d17b-8f0d-420e-b658-d4482.... In step 7 - add initial data, I added the data as per the tutorial though I observed that the "cds add data" command created ; separated fields. So, I changed my data like below. 

my.bookshop-Authors.csv

ID;name
101;Emily Brontë
107;Charlote Brontë
150;Edgar Allen Poe
170;Richard Carpenter

my.bookshop-Books.csv where I changed the column separators as , instead of ;

ID,title,author_ID,stock
201,Wuthering Heights,101,12
207,Jane Eyre,107,11
251,The Raven,150,333
252,Eleonora,150,555
271,Catweazle,170,22

But as soon as I save those files, I get below errors in cds watch

[Error: ENTITY_ALREADY_EXISTS] {
errno: 19,
code: 400,
originalMessage: 'SQLITE_CONSTRAINT: UNIQUE constraint failed: my_bookshop_Authors.ID',
numericSeverity: 4
}

Please help. SAP Cloud Application Programming Model 

Thanks,

Mainak

6 REPLIES 6

MattBrightman
Explorer
0 Kudos
896

Are you able to please provide screenshots of your schema? 

0 Kudos
862

Hi Matt, 

Sure, basically I just copied the same schema as copied from the same tutorial. I am pasting my schema.cds below. 

namespace my.bookshop;
using { Country, managed } from '@sap/cds/common';

entity Books {
  key ID : Integer;
  title  : localized String;
  author : Association to Authors;
  stock  : Integer;
}

entity Authors {
  key ID : Integer;
  name   : String;
  books  : Association to many Books on books.author = $self;
}

entity Orders : managed {
  key ID  : UUID;
  book    : Association to Books;
  country : Country;
  amount  : Integer;
}

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos
834

Have you already loaded the data once?  This looks to me like its saying the record with that unique key already exists. 

0 Kudos
741

Hi Thomas,

How to check in SQLITE3 if the data already exists? Otherwise how to clear/drop the tables?

Thanks,

Mainak

0 Kudos
56

Hi Mainak,

It seems in you entity key value are duplicating for AuthorID in Book entity.

Just changed the key value by adding some random number at end any try? it may work.

 

Thanks 

dheerendras
Discoverer
0 Kudos
58

any solution?