cancel
Showing results for 
Search instead for 
Did you mean: 

CAP - DB Deployer failing after renaming a column of an entity

Mohit_Agarwal
Associate
Associate
0 Kudos

Hi everyone,

I have been working on a CAP Node.js project where I have an order entity. My MTA project is deployed to BTP and running successfully.

I made a spelling error in a column of the order entity in schema.cds file. If you look closely, earlier it was 'empdigitialid'. Now I have corrected it to be 'empdigitalid'. After renaming the entity, when I try to deploy the artifacts, it is failing with the following error:

com.sap.hana.di.table: Database error 287: cannot insert NULL or update to NULL: EMPDIGITALID: line 1 col 1 (at pos 0)

Old schema:

Mohit_Agarwal_1-1681218401846.png

Updated schema:

Mohit_Agarwal_0-1681218343056.png

Log file:

Mohit_Agarwal_3-1681218537697.png

Link to log file: cafti-cds-db-deployer.log

Please let me know if you need any other details.

Thanks!!

Accepted Solutions (0)

Answers (2)

Answers (2)

hjb
Advisor
Advisor
0 Kudos

No schema migration tool in the world is capable of recognising column renaming based on the input of two CREATE TABLE statements (the first one describing the current and the second one the new/changed table). The only thing a machine can do is to create new columns and try to copy the content of the existing columns into the new ones. In hdbtable that's done by creating a shadow table and copying the full table content.

In your case you are lucky because the new column is a NOT NULL primary key. This means that the database can't insert the existing record into the new table without to the old column and filling the new key value with null is just not allowed. Instead the deployment transaction has been rolled back and no content has been destroyed.

A default value for that key column is not an option as it would silently replace your existing data with just that, the meaningless default value.

So how can you preserve the columns content?

1) Rename that column directly in the database by executing an ALTER TABLE ... RENAME statement manually such that it represents the changed entity in your CDS model or

2) Convert the hdbtable into an hdbmigrationtable file (read capire and '@cds.persistence.journal' for details) and

edit the DROP/ADD column pair into a RENAME statement.

3) Live with the wrong column name and add a mapping view that renames the column

HTH

divyeaggarwal
Explorer
0 Kudos

Hi Mohit

It might be because there is some entry in the table database. Please delete all the database entries and deploy again. It should work.

Regards

Divye

Mohit_Agarwal
Associate
Associate
0 Kudos

Hi Divye,

Thanks for the clarification.

Yes, there are entries in the database. But, if you see line number 523 of the log file, it says

"CAFTI_ORDER": the table contains data; recreating it and copying the data (STDOUT, APP/TASK/deploy)#"

This shows that CAP takes care of the data itself. It's just that it failed while migrating the DB object, as visible in the next line:

Error: com.sap.hana.di.table: "CAFTI_ORDER": could not migrate the database object [8250019] (STDOUT, APP/TASK/deploy)#

I am really not sure if I am supposed to delete all the entries for making a change to the column name. Do you know of any way to do this without losing the entries of the table?

Thanks for your help!!

Regards,

Mohit