Deleting a Space is Not Working Due to Foreign Key Constraint
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Symptoms
One or more users are not able to remove their personal space. The following appears in the atlassian-confluence.log
:
2013-08-22 16:54:53,743 ERROR [Long running task: Space removal long running task] [atlassian.event.internal.AsynchronousAbleEventDispatcher] run There was an exception thrown trying to dispatch event 'com.atlassian.confluence.event.events.space.SpaceWillRemoveEvent[source=com.atlassian.confluence.spaces.DefaultSpaceManager@133f8fe7]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.atlassian.confluence.core.listeners.BundledContentSpaceRemovalListener.spaceIsBeingRemoved(com.atlassian.confluence.event.events.space.SpaceWillRemoveEvent), listener=com.atlassian.confluence.core.listeners.BundledContentSpaceRemovalListener@62eafc48}'.
-- referer: http://<url>/conf/spaces/removespace.action?key=~amelie.westerberg | url: /conf/spaces/doremovespace.action | userName: admin | action: doremovespace | space: 786467
java.lang.RuntimeException: Hibernate operation: could not delete: [com.atlassian.confluence.pages.Page#2459182]; SQL []; Cannot delete or update a parent row: a foreign key constraint fails (`confluence_test`.`notifications`, CONSTRAINT `FK594ACC88C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `content` (`CONTENTID`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`confluence_test`.`notifications`, CONSTRAINT `FK594ACC88C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `content` (`CONTENTID`))
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:66)
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1.execute(AsynchronousAbleEventDispatcher.java:32)
....
Caused by: org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not delete: [com.atlassian.confluence.pages.Page#2459182]; SQL []; Cannot delete or update a parent row: a foreign key constraint fails (`confluence_test`.`notifications`, CONSTRAINT `FK594ACC88C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `content` (`CONTENTID`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`confluence_test`.`notifications`, CONSTRAINT `FK594ACC88C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `content` (`CONTENTID`))
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:100)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.orm.hibernate.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:364)
at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:351)
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`confluence_test`.`notifications`, CONSTRAINT `FK594ACC88C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `content` (`CONTENTID`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
....
Diagnosis
As can be seen from the error, Confluence is not able to delete Page ID 2459182:
Hibernate operation: could not delete: [com.atlassian.confluence.pages.Page#2459182]
Try to navigate your browser to <confluence-url>/pages/viewpage.action?pageId=2459182
. If this particular page is historical/version page, then proceed to the resolution
Cause
Confluence is not able to delete the offending historical/version page, as one or more users are watching the page.
Resolution
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
- Backup your Confluence database
- Stop Confluence
Replace
xxxx
with the page ID of the affected page for the following SQL query and run this query in your Confluence databasedelete from notifications where contentid=xxxx
This will delete all watchers for the affected page
- Start Confluence and remove the personal space again