Exceptions in cloud deployment

I’m trying to deploy my app in cloud but getting the following error. It seems an entity that I have removed already id still referred from somewhere. I have used finder in IntelliJ, removed from everywhere. It is only available in database scripts for unknown reasons.
How can I clean it?

Caused by: java.lang.RuntimeException: An error occurred while executing SQL script at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.executeSqlScript(DbUpdaterEngine.java:345) at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.executeScript(DbUpdaterEngine.java:403) at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.doUpdate(DbUpdaterEngine.java:228) at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.doUpdate(DbUpdaterImpl.java:104) ... 24 more Caused by: org.postgresql.util.PSQLException: ERROR: relation 
"erp_budget_version" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455) at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155) at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430) at 
org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:303) at 
org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:289) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:266) at 
org.postgresql.jdbc.PgStatement.execute(PgStatement.java:262) at org.apache.tomcat.dbcp.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:294) at 
org.apache.tomcat.dbcp.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:294) at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.executeSql(DbUpdaterEngine.java:358) at 
com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.executeSqlScript(DbUpdaterEngine.java:342) ... 27 more  30-Jun-2017 04:53:55.852 INFO

Hi Mortoza,
Studio generates scripts comparing database and the project model. If the state of the Cloud database differs from your local one, such problems might occur. Assumably at some moment, the application was deployed to Cloud without generating the DB-scripts.
Let me explain how DB in Cloud is automatically updated.

  1. When you launch Generate DB scripts in Studio. Update-scripts are generated and put to the modules/core/db/update/%DBMS% folder. Init-scripts are also updated.
  2. Deployment to Cloud consists of two steps: jelasticBuildWar and jelasticDeployWar. You can launch them separately.
    2.1) jelasticBuildWar Gradle task assembles scripts from the project and its components (see core/build/db).
    The built WAR-file appears in the build/distributions/war folder. Using file archiver you can browse its contents. Db scripts are inside the WEB-INF directory.
    2.2) jelasticDeployWar uploads and deploys the WAR to Cloud.
  3. When the application starts DbUpdaterEngine compares the contents of folder with DB-scripts and records in sys-db-changelog if some of the update scripts was not applied (there is no corresponding record in sys-db-changelog). The script is executed and if successful new record is written to sys-db-changelog. So the script is marked as executed.
    See also the documentation.
    To fix the problem you need to manage the Cloud Db and(or) DB update-scripts manually. Examine your scripts and DB and find what is wrong. To correct the DB state:
    a) you can modify the generated by Studio scripts, before or after execution on your local database
    b) you can build WAR, manage the scripts manually, and then deploy the WAR to Cloud
    c) Using PHP PgAdmin you can manually add the unnecessary scripts to sys-db-changelog
    Also, you can enable global access to your Cloud DB, adjust connection to it in Studio and generate DB -scripts. But this way is considered bad as you should not use porduction DB at development time.

Thanks for the help. It will be helpful in future in production. I had to recreate everything in cloud Dev environment to move on and its working well.