Search code examples
openbravo

Openbravo foreign key not found issue while doing update.database


Issue while doing a update.database in openbravo

[java] ALTER TABLE AD_FIELD [java] ADD CONSTRAINT AD_COLUMN_FIELD FOREIGN KEY (AD_COLUMN_ID) REFERENCES AD_COLUMN (AD_COLUMN_ID)

[java] 250661 ERROR - Not all the commands in the final update step were executed correctly. This likely means at least one foreign key was not activated successfully. Please review which one, and fix the missing references, or recover the backup of your sources. [java] java.lang.Exception: There were serious problems while updating the database. Please review and fix them before continuing with the application rebuild [java] at org.openbravo.ddlutils.task.AlterDatabaseDataAll.doExecute(AlterDatabaseDataAll.java:227) [java] at org.openbravo.ddlutils.task.BaseDatabaseTask.execute(BaseDatabaseTask.java:86) [java] at org.openbravo.ddlutils.task.AlterDatabaseJava.main(AlterDatabaseJava.java:38)`


Solution

  • Please execute the below query in your database

    select AD_FIELD_ID  from AD_FIELD where AD_COLUMN_ID not in (select  AD_COLUMN_ID from AD_COLUMN);
    

    The output columns are missing foreign key AD_COLUMN_ID in the AD_FIELD table.

    Go to modulepath/src-db/database/sourcedata/AD_FIELD.xml

    search for individual AD_FIELD_ID from above query output and delete from the AD_FIELD.xml file and do update.database again.