This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 236580 - Deleting tables fails due to foreign key constraints
Summary: Deleting tables fails due to foreign key constraints
Status: VERIFIED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: matthias42
URL:
Keywords: PATCH_AVAILABLE
Depends on:
Blocks:
 
Reported: 2013-10-01 06:30 UTC by Petr Jiricka
Modified: 2015-02-09 15:00 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
proposed patch v1 (14.29 KB, patch)
2014-08-11 20:16 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2013-10-01 06:30:05 UTC
1. Open some sample database in NetBeans DB node that contains foreign key constraints
2. Select all tables and delete them

=> Deleting typically fails, complaining that it can not delete some tables due to referential integrity constraints. 

Workaround is to delete the "higher" tables first, and then the "lower" tables. 
The fix should be if the IDE did that for you - figure out the table relationships and delete them in the right order.
Comment 1 matthias42 2014-08-11 20:16:59 UTC
Created attachment 148646 [details]
proposed patch v1

The attached patch should cure the problem by hooking into the existing DbExtendedDelete class. Currently this class is mostly used to introduce a user confirmation dialog.

This patch takes the selected table nodes, seperates them based on the connection they are from. For each connection the tables nodes are topologicaly sorted, so that the tables that depend on other tables are deleted first.

As long as there are no cyclic dependencies this should solve the case. For the cyclic case this does not worsen the situation but reports it to the user. The user can than react to this.
Comment 2 matthias42 2015-02-07 21:52:58 UTC
The proposed patch was merged as:

https://hg.netbeans.org/core-main/rev/a59e261f2fee

in the next few days a nightly build will be created, that contains this change (a message is placed here then). My tests are positive and the idea is exactly as proposed (sort tables by dependency and delete in order). Please test that version. If you find it fixes your problem, please change the status of this bug to VERIFIED.

Please note: This does not fix the issue of cyclic dependencies. These still need to be broken up manually.
Comment 3 Quality Engineering 2015-02-09 02:23:06 UTC
Integrated into 'main-silver', will be available in build *201502090001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/a59e261f2fee
User: Matthias Blaesing <matthias42@netbeans.org>
Log: #236580: Make table deletion more reliable by ordering deletes based on table dependencies
Comment 4 Jiri Kovalsky 2015-02-09 15:00:29 UTC
Product Version: NetBeans IDE Dev (Build 201502090001)
Java: 1.8.0_25; Java HotSpot(TM) 64-Bit Server VM 25.25-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b17
System: Linux version 3.13.0-24-generic running on amd64; UTF-8; en_US (nb)

I tried steps described by Petr and it was possible to delete all tables without any warnings. Thanks for the fix Matthias!