cancel
Showing results for 
Search instead for 
Did you mean: 

@assert.integrity not enforcing foreign key constrainsts.

anonymoushm
Explorer
0 Kudos

Hi Colleagues,

We have the below schema.cds

entity A {
key a1: String;
b: Composition of many B on b.b2 = $self;
}

entity B {
key b1: String;
key b2: Association to one A @assert.integrity;
}

But when we run cds compile schema.cds --to sql I do not see foreign key, also they are not present and enforced when checked after deployment to hana db. Any idea what might be going wrong?

CREATE TABLE com_sap_acrs_definereport_A (
  a1 NVARCHAR(5000) NOT NULL,
  PRIMARY KEY(a1)
);

CREATE TABLE com_sap_acrs_definereport_B (
  b1 NVARCHAR(5000) NOT NULL,
  b2_a1 NVARCHAR(5000) NOT NULL,
  PRIMARY KEY(b1, b2_a1)
);

Accepted Solutions (1)

Accepted Solutions (1)

marcbecker
Advisor
Advisor

You explicitly need to enable generation of foreign key constraints on the database for your project in an additional global setting in your .cdsrc.json file.

{
  ...
  "features": {
    "assert_integrity": "db"
  }
  ...
}

See section Database Constraints, which is also linked from the @assert.integrity documentation.

anonymoushm
Explorer
0 Kudos

Got it working! Thanks

manu_bhai
Explorer
0 Kudos

Thanks a lot. I was also struggeling on this.

Answers (0)