Grails cannot create table because it 'already exists'

Was your grails v1.1 app just working and suddenly reports something like this whenever you fire it up? I bet your data source is set to 'create-drop' too.
2009-05-12 17:32:09,671 [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table foo (id int8 not null, ...
2009-05-12 17:32:09,672 [main] ERROR hbm2ddl.SchemaExport  - ERROR: relation "foo" already exists
2009-05-12 17:32:09,694 [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table bar (id int8 not null, ...
2009-05-12 17:32:09,694 [main] ERROR hbm2ddl.SchemaExport  - ERROR: relation "bar" already exists
2009-05-12 17:32:09,695 [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table myfoo (id int8 not null,...
2009-05-12 17:32:09,695 [main] ERROR hbm2ddl.SchemaExport  - ERROR: relation "myfoo" already exists
2009-05-12 17:32:09,703 [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table mybar (id int8 not null,...
2009-05-12 17:32:09,703 [main] ERROR hbm2ddl.SchemaExport  - ERROR: relation "mybar" already exists
Well you're in luck. I've discovered three possible causes and they're all easy to fix:
  • Your database is locked by an existing grails process.  This happens to me sometimes when I close my IDE (IntelliJ) without killing the process.  Just kill the orphaned process to resolve this.
  • You have some DB tool connected to your database which is preventing the drop command from being executed.  Simply close all of your database tools.
  • You are attempting to do a backwards migration.  If you have moved from a new schema to an older one (revisiting an old tag, for instance) Grails may not be able to drop the DB.  Drop and recreate it by hand.
If none of these work, and you find another root cause, please drop me a comment and I'll update this list.
0 Votes