Reputation: 331
I have the ER diagram. I try describe it like grails domains, but after start project just part of tables exist(created). I can't find in which place I made a mistakes.
I use MySQL database, after start only song_tag table crated
ERD http://imagizer.imageshack.com/img661/4805/ke6jBx.png
My grails domains
class Song {
static hasMany = [audios: Audio, tags: Tag]
BigInteger id
String title
String chorus
Boolean chorusRepeat
Date created
Date updated
static constraints = {
tags joinTable:[name:'song_tag', key:'song_id']
}
}
class Tag {
static belongsTo = Song
static hasMany = [songs: Song]
BigInteger id
String name
static constraints = {
songs joinTable:[name: 'song_tag', key: 'tag_id']
}
}
class Couplet {
static belongsTo = Song
BigInteger id
String text
Song song
static constraints = {
}
}
class Audio {
static belongsTo = Song
BigInteger id
String audio
String type
Date created
Date updated
Song song
static constraints = {
}
}
Console output
2015-02-01 14:20:36,007 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table couplet (id decimal(19,2) not null auto_increment, version bigint not null, song_id decimal(19,2) not null, text varchar(255) not null, primary key (id)) ENGINE=InnoDB Error | 2015-02-01 14:20:36,007 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - Incorrect column specifier for column 'id'
Thank you
Upvotes: 1
Views: 224
Reputation: 4373
There are two things which has to be changed
1)
static constraints = {
songs joinTable:[name: 'song_tag', key: 'tag_id']
}
it should be in mapping closure and not in constraints closure
static mapping = { songs joinTable:[name: 'song_tag', key: 'tag_id']}
2) just remove id field from domain, it will automatically created by Gorm.
Upvotes: 1