Home > Software engineering >  Flyway Repeatable Script Throwing Table Does Not Exist Error
Flyway Repeatable Script Throwing Table Does Not Exist Error

Time:09-29

I am currently trying to trim down my versioned scripts into one baseline script (we don't pay for flyway so is a pain). So I deleted my schema and attempted to run my one big script that contains everything I had. I exported the DDL out of my DBeaver client. However when starting my applications I am getting this error:

SQL State  : 42P01
Error Code : 0
Message    : ERROR: relation schema-name.my_table_name does not exist
  Position: 13
Location   : db/migration/aaa/R__01_my_script_name.sql 
Line       : 3
Statement  : DELETE FROM "schema-name.my_table_name" WHERE field_name = 'blah' OR field_name = 'blah2'

I beleive this error is because the repeatable script is running before the versioning, where as the versioning script is what creates all of the tables. It is my understanding that flyway runs the repeatable scripts last. Is there some sort of property I am missing or something? Here is my directory structure:

db
 --> migration
     --> my client
       -->R__01_repeatable.sql
       -->V__01_baseline.sql

Please let me know if you need anymore information from my here is my flyway properties

  flyway:
    locations: classpath:/db/migration/shared,classpath:/db/migration/${app.client}
    baseline-on-migrate: true
    base_line_version: 1
    placeholders:
      schema-name: ${spring.jpa.properties.hibernate.default_schema}
    schemas: ${spring.jpa.properties.hibernate.default_schema}
    enabled: true

CodePudding user response:

Looking at your scripts, your V script is named incorrectly

The naming convention is documented here

In particular, the double underscore needs to appear after the V, so the correct name would be V01__baseline.sql

Repeatable migrations run after Versioned migrations, so this should fix the problem once the Versioned migration is properly detected

  • Related