cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP project with persistent database: Error - missing localized_* tables

iashishsingh
Participant
5,024

Hello,

I am trying to run the sample bookshop app provided in the SAP CAP samples(https://github.com/SAP-samples/cloud-cap-samples). It runs as expected when using the default in-memory sqlite database (which is the default setting). If I try to change the settings to use a persistent sqlite database, the services are throwing errors of form:

SQLITE_ERROR: no such table: localized_<service-name>_<entitiy-name>
http://localhost:4004/browse/Books


<error xmlns="http://docs.oasis-open.org/odata/ns/metadata">
<code>500</code>
<message>SQLITE_ERROR: no such table: localized_CatalogService_Books</message>
</error>

Following is a step by step detail of what I've done. Any insight into what might be going wrong and how to fix it would be very much appreciated. Thanks!

Clone sample apps from https://github.com/SAP-samples/cloud-cap-samples

cd cloud-cap-samples/
npm i
npm run bookshop

The default configuration runs the sqlite database in-memory. In order to use the persistent database, do following changes:

cd packages/bookshop
cds deploy --to sqlite:my.db

The cds deploy command will create a persistent database and fill the necessary tables using sample CSV data files. It also updates the package.json with cds configuration to use a persistent database instead of the default in-memory database. You should see console messages like following:

> filling sap.capire.bookshop.Authors from db/data/sap.capire.bookshop-Authors.csv
 > filling sap.capire.bookshop.Books from db/data/sap.capire.bookshop-Books.csv
 > filling sap.capire.bookshop.Books_texts from db/data/sap.capire.bookshop-Books_texts.csv
 > filling sap.capire.bookshop.OrderItems from db/data/sap.capire.bookshop-OrderItems.csv
 > filling sap.capire.bookshop.Orders from db/data/sap.capire.bookshop-Orders.csv
 > filling sap.common.Currencies from db/data/sap.common-Currencies.csv
 > filling sap.common.Currencies_texts from db/data/sap.common-Currencies_texts.csv
/> successfully deployed to ./my.db
 > updated ./package.json

The package.json should have an updated "cds" section as follows -

"cds": {
    "requires": {
      "db": {
        "kind": "sqlite",
        "model": "db/schema.cds",
        "credentials": {
          "database": "my.db"
        }
      }
    }
  }

Now, if we trigger command 'cds run', the cds should start serving using the persistent database.

cds run
[cds] - connect to datasource - sqlite:my.db
[cds] - serving AdminService at /admin
[cds] - serving CatalogService at /browse - with impl: srv/cat-service.js
[cds] - service definitions loaded from:


  app/index.cds
  srv/admin-service.cds
  srv/cat-service.cds
  app/admin/fiori-service.cds
  app/browse/fiori-service.cds
  app/orders/fiori-service.cds
  app/common.cds
  db/schema.cds
  ../../node_modules/@sap/cds/common.cds


[cds] - launched in: 1303.835ms
[cds] - server listening on http://localhost:4004

Now, if you go to link http://localhost:4004/browse/Books, it shows following error:

<error xmlns="http://docs.oasis-open.org/odata/ns/metadata">
<code>500</code>
<message>SQLITE_ERROR: no such table: localized_CatalogService_Books</message>
</error>
qmacro
Developer Advocate
Developer Advocate

Great question, well formed and lots of detail. Nice work!

iashishsingh
Participant

Hi dj.adams.sap and thanks! Have learned a lot from your live recordings which I discovered very recently on Youtube. Can't appreciate you enough for the efforts you have been making!

NicolasSchwarz
Explorer
0 Kudos

Hey, I faced the same problem with the localized-error. Did you find a solving?

MattRook
Explorer
0 Kudos

Hi I know this is an old post but I am currently doing this same training project and I have the same issue. I'm surprised there isn't a more definitive solution 4 years later but I got it to work. I have had this problem before on other frameworks and the problem lies in the package-lock.json file. Delete that file, do an 'npm install' and redeploy with 'cds deploy'. That should refresh the package-lock file and update all the settings and work.

Accepted Solutions (1)

Accepted Solutions (1)

chgeo
Advisor
Advisor

Could you change the `model` property in package.json to

"model": ["db", "srv"]

and try again?

iashishsingh
Participant
0 Kudos

Hi Christian. Thanks for your suggestion! I tried changing it to

"model": ["db", "srv"]

but getting the same error as before. To make it easier for the error to be reproduced, I've pushed my changes under a fork of cloud-cap-samples repo here: https://github.com/git-ashish/cloud-cap-samples. The changes have been made to packages/bookshop folder.

Thanks.

chgeo
Advisor
Advisor

We have analysed the issue and will fix it in the next release (around next week). As a workaround you can revert this commit in the bookshop repository.

Anyways, thanks for reporting!

iashishsingh
Participant
0 Kudos

Thanks Christian! Reverting this commit did not solve the error but looking forward the fix in the next release!

jalf1991
Explorer

Hi @christian.georgi

the issue is with this package.json file. I delete this lines in the json and all run fine:

"requires": { "db": { "kind": "sqlite", "model": [ "db", "srv" ], "credentials": { "database": "sqlite.db" } } }

Answers (3)

Answers (3)

former_member643578
Participant

Instead of cds run command try the following command

npx nodemon -e cds,csv,properties -w app -w db -x "cds deploy && cds run"

0 Kudos

This really does the trick. Thanks!

jasonmuzzy
Active Participant
0 Kudos

This really does work, thank you! Can you explain what this command is doing differently than just normal cds deploy followed by cds run?

david_kunz2
Product and Topic Expert
Product and Topic Expert

Dear Ashish,

Thanks for reporting this issue, it seems like a bug!
Which version of `@sap/cds` are you using? You can find this information by typing `cds -v`.

I tested it with `@sap/cds: 3.21.3` and it works fine.

Thanks and best regards,
David

iashishsingh
Participant
0 Kudos

Hi David,

Thanks for your quick reply!

My machine also has the same 3.21.3 version. Here is the output of `cds -v`:

@sap/cds-dk: 1.4.4
@sap/cds: 3.21.3
@sap/cds-compiler: 1.21.1
@sap/cds-foss: 1.1.0
@sap/cds-messaging: 1.5.0
@sap/cds-reflect: 2.9.2
@sap/cds-rest: 1.3.0
@sap/cds-services: 1.22.0
@sap/generator-cds: 2.11.1
Node.js: v10.16.0<br>

The bookshop/package.json has "@sap/cds": "latest" under "dependencies".

Sorry, I did not clearly understand you. Is it a bug in cds or does it look like a setup issue at my end?

Thanks David!

iashishsingh
Participant
0 Kudos

Some additional information:

If I deploy the same app to SAP HANA cloud using the guide: https://cap.cloud.sap/docs/advanced/deploy-to-cloud, the service works fine as expected. The issue appears to be occurring when using the persistent database as sqlite.

hschaefer123
Participant
0 Kudos

Hi,
i have similar issues after deployment to CFm but just using in-memory db!