我在Grails中创建了一些域类。
项目:
package localetool
class Project {
String name
Date createDate
Date updateDate
static belongsTo = [appUser: AppUser]
//static belongsTo = AppUser <- this works right
static hasMany = [res: Res, books: Book]
static mapping = {
sort "updateDate"
}
static constraints = {
name unique: true, blank: false
}
}
和AppUser:
package localetool
import com.kyt.auth.User
class AppUser {
static hasMany = [projects: Project]
User user
static constraints = {
}
}
这会在启动应用程序时导致错误并使用appUser.projects:
Unknown column 'projects0_.app_user_id' in 'field list'
当我在没有appUser的情况下使用belongsTo时,它工作正常,但我希望能够访问父级。
答案 0 :(得分:2)
确保grails更新您的数据库。由一些GUI客户端(如HeidiSQL for MySQL)打开并验证它