Monday, January 18, 2010

Grails unable to create or alter a SQL table

To get to the point, the lesson learned here is, "be careful how you name your fields". When Grails updates the table schema due to changes you make in the Domain class, Grails returns this cryptic message:

Running Grails application..
2010-01-18 11:19:59,779 [main] ERROR hbm2ddl.SchemaExport - Unsuccessful: create table stock (id bigint not null auto_increment, version bigint not null, change float not null, price float not null, symbol varchar(255) not null, primary key (id))
2010-01-18 11:19:59,780 [main] ERROR hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'change float not null, price float not null, symbol varchar(255) not null, prima' at line 1

Obtaining the exact SQL can be tricky, but the cause was in how I named the table columns. When I changed "change" to "changePerc" and "price" to "priceDollars" everything worked.

No comments:

Post a Comment