【问题标题】:Cannot delete User in GORM无法在 GORM 中删除用户
【发布时间】:2017-10-17 22:13:03
【问题描述】:

当我尝试在 GORM 中删除受访者时出现此错误:

Referential integrity constraint violation: "FK_APCC8LXK2XNUG8377FATVBN04: 
PUBLIC.USER_ROLE FOREIGN KEY(USER_ID) REFERENCES PUBLIC.USERS(ID) (40)"; 
SQL statement: delete from users where id=? and version=? [23503-176]

这是我的域名:

package com.cgi.recruitmenttest

import com.cgi.security.User

class Interviewee extends User{

String firstName
String lastName
String email
String telephone
String level
static hasMany = [results:Result,tests:TestInterviewe]

static constraints = {
    lastName()
    firstName()
    email(email: true)
    telephone(nullable: true)
    level inList: ['Debutant', 'Confirme', 'Expert']
}

}

我只是尝试创建一个没有结果和测试的受访者,但是当我删除时,我得到了这个错误..

有人可以帮忙吗?谢谢

【问题讨论】:

  • 你是怎么删除的?
  • 我用脚手架的默认方法删除

标签: grails spring-security grails-orm


【解决方案1】:

您想从USERS 表中删除一个数据,但在USER_ROLE 表中它包含USERS 表的外键(名为USER_ID)。这就是您无法删除的原因。先根据USERS的表ID删除USER_ROLE表的数据,然后就可以删除了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-21
    • 2015-12-05
    • 2018-02-01
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    相关资源
    最近更新 更多