gpt4 book ai didi

mysql - 从 ER 图创建 grails 域

转载 作者:行者123 更新时间:2023-11-29 00:04:15 25 4
gpt4 key购买 nike

我有 ER 图。我尝试将其描述为 grails 域,但在启动项目后,只有部分表存在(创建)。我找不到我在哪个地方犯了错误。

我用的是MySQL数据库,启动后只创建了song_tag表

ERD http://imagizer.imageshack.com/img661/4805/ke6jBx.png

我的 grails 域

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 = {
}
}

控制台输出

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'

谢谢

最佳答案

有两点需要修改

1)

 static constraints = {
songs joinTable:[name: 'song_tag', key: 'tag_id']
}

它应该在映射闭包中而不是在约束闭包中

static mapping = {  songs joinTable:[name: 'song_tag', key: 'tag_id']}

2) 只需从域中删除 id 字段,它将由 Gorm 自动创建。

关于mysql - 从 ER 图创建 grails 域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28262725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com