Grails 2.4.4数据源“创建 - 删除”无法删除所有具有FK的表 [英] Grails 2.4.4 DataSource "create-drop" fails to drop all tables having FKs

查看:81
本文介绍了Grails 2.4.4数据源“创建 - 删除”无法删除所有具有FK的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有一个问题,我正面临着DataSource的create-drop配置,使用MySQL作为数据源。



每当我发出一个 grails stop-app ,架构中剩下22个表。



启用Hibernate类的调试模式后,在停止应用程序进程结束时,它会生成<$ c $对于所有35个表,如果存在< tablename> ,则在日志中不存在错误/确认。



剩下的表格具有FK关联,并且需要按特定顺序移除它们。使用相同的Domain类结构,我从来没有遇到早期版本(2.2.0)的这个问题。



现在我正在手动删除 - 每次在run-app之前创建因为这会导致BootStrap数据出现问题。



任何用于调试此问题的指针或用于发生此情况的用例时,都应该感激。

$ b $对于我的情况设置MySQL的FK检查为0(v5.5.25)解决了这个问题,虽然我不完全确定我是否应该< SET FOREIGN_KEY_CHECKS = 0



如果有人有更好的解决方案,请分享。
$ b

编辑

由于这个。获得的教训 - 不要盲目复制粘贴随机代码〜: - /



ANSWER



感谢伯特。

如果数据库的行为不正常,则执行w.r.t ddl操作。始终检查由 grails schema-report 生成的 ddl.sql ,它应该具有以下结构

  alter table<表格>丢弃约束<约束> 
...

drop table if exists< Table>
...

create table< Table>(...)
...

create index< Index> ... - (如果有的话)
...

改变表格<表格>添加约束<约束>
....


Using Grails 2.4.4, and have ported my domain classes from 2.2.0.

There's a problem I am facing w.r.t "create-drop" config of DataSource, using MySQL as the datasource.

Whenever I issue a grails stop-app command, out of total 35 tables, 22 tables are left in the schema.

After enabling debug mode for Hibernate classes, and at the end of the stop-app process, it was generating drop table if exists <tablename> for all 35 tables, but no error/confirmation was there in the logs whether the drop table succeeded or not.

The tables left are having FK associations, and they need to be removed in specific order. With same Domain class structure, I never had this problem with earlier (2.2.0) version of grails.

Right now I am manually dropping-creating everytime before run-app as it's causing trouble with the BootStrap data.

Any pointer to debug this issue or a usecase for when this can happen, shall be appreciated.

解决方案

For my case setting FK-checks to 0 for MySQL (v5.5.25) solved this, although I am not entirely sure if I am supposed to SET FOREIGN_KEY_CHECKS=0 at all.

If anyone has a better solution, please do share.

EDIT

The problem was faced due to this. Lesson learnt - Thou shalt not copy-paste random code mindlessly ~:-/

ANSWER

Thanks Burt.

If DB is behaving erratically w.r.t ddl operations. Always check ddl.sql generated by grails schema-report, which should ideally have following structure

alter table <Table> drop constraint <Constraint>
...

drop table if exists <Table>
...

create table <Table>(...)
...

create index <Index> ...   --(if any)
...

alter table <Table> add constraint <Constraint>
....

这篇关于Grails 2.4.4数据源“创建 - 删除”无法删除所有具有FK的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆