Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Grails domain class is not creating a table in the database

I just created a new grails domain class on a project I just started working on. I know the datasources are setup correctly since we already have a bunch of domain classes that are updating to the database just fine.

The error I get:

Caused by BatchUpdateException: ORA-00942: table or view does not exist

I tried running DBMUpdate but that also did not create the table.

Is there something I'm missing with creating domain classes? Do I need to change something in the changelog ? Any advise would be helpful!

like image 789
Brandon Wagner Avatar asked Jul 09 '13 15:07

Brandon Wagner


1 Answers

The easiest thing would be to add dbCreate = "update" to your DataSource.groovy. A better thing would be to use the database-migrations plugin for your app.

Regarding manually creating tables, the convention grails following by default is to underscore camelcase. For example, given the following domains:

class User {
  String firstName
  String lastName 
  static hasMany = [addresses: Address]
}

class Address {

  static belongsTo = [user: User]
}

You would end up with the following tables:

user
---------
id
version
first_name
last_name
---------

address
---------
id
version
user_id
---------
like image 111
Gregg Avatar answered Sep 28 '22 07:09

Gregg