2
votes

I'm trying out Flyway to potentially use in our project and so I have an extremely simple migration script. I appear to have set something up incorrectly however - flyway connects to my DB (SQL Server 2008 R2) successfully to create metadata tables, but when I run the script I get

 [ERROR] Failed to execute goal com.googlecode.flyway:flyway-maven-plugin:2.2.1:migrate      (default-cli) on project persistence: com.googlecode.flyway.cor
 e.api.FlywayException: Migration of schema [dbo] to version 1.1 failed! Changes successfully rolled back. Incorrect syntax near '?'. -> [Help 1]

My script is:

 ALTER TABLE msg.Message
 ADD Deleted bit NULL

Looking at the debug logs, flyway outputs:

 [DEBUG] Executing SQL: ??A L T E R   T A B L E   m s g . M e s s a g e

  A D D   D e l e t e d   b i t   N U L L

I don't know where the question marks come from, or why the text has spaces. Any ideas?

3
I am not too confident with Flyway, but are you not required to end your SQL statements with a ;? As your script is a SQL file ... - cheffe
Could this be an encoding problem? Flyway expects UTF-8. Which one did you use? - Axel Fontaine
It was in UTF-8 it turns out - I'm using files generated by SQL Server Management Studio 2008. My individual scripts are running correctly now, but my initial DB migration fails all over. For now I'm just going to handle the initial migration by hand and let Flyway handle the patch scripts. - Evan Knowles
Have you tried changing the encoding property to the correct value for your environment? - Axel Fontaine
I think it was something related to that - it appears to be working fine now, thanks. - Evan Knowles

3 Answers

2
votes

That kind of output indicates UTF, but in the 16-bit form, with a magic character at the beginning. The ? and spaces are the giveaway.

Several MS tools speak that natively, while most Unix tools use UTF-8.

1
votes

Changing the encoding of the sql migration file to UTF-8 solved the '??' error for me.

1
votes

Changing the encoding for the file worked for me. I used a text editor (Notepad++):

  1. Open the file in the text editor.
  2. Select 'Encoding' in the menu.
  3. Choose the encoding type from the list of options.
  4. Save the file.