问题
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.
回答1:
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>
....
来源:https://stackoverflow.com/questions/28016256/grails-2-4-4-datasource-create-drop-fails-to-drop-all-tables-having-fks