Confluence update 3.5.13 to 4.0: Failed to add constraint fk_app_dir_group_app
Asked by Aaron McClimont:

I have tried to update Confluence 3.5.13 to 4.0, and have recieved the following error during the Schema Update.

We're using MS SQL Server 2008.

Can anyone provide some assistance?

Thanks.

```
2011-09-21 14:41:52,695 ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute Unsuccessful: alter table cwd_app_dir_group_mapping add constraint fk_app_dir_group_app foreign key (application_id) references cwd_application2011-09-21 14:41:52,695 ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute Foreign key 'fk_app_dir_group_app' has implicit reference to object 'cwd_application' which does not have a primary key defined on it.2011-09-21 14:41:52,695 ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute could not complete schema updatecom.microsoft.sqlserver.jdbc.SQLServerException: Foreign key 'fk_app_dir_group_app' has implicit reference to object 'cwd_application' which does not have a primary key defined on it.	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:775)	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:633)	at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)	at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)	at net.sf.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:167)	at bucket.core.persistence.hibernate.schema.SchemaHelper.updateSchemaIfNeeded(SchemaHelper.java:161)	at bucket.core.persistence.hibernate.schema.SchemaHelper.updateSchemaIfNeeded(SchemaHelper.java:134)	at com.atlassian.confluence.upgrade.AbstractUpgradeManager.upgrade(AbstractUpgradeManager.java:93)	at com.atlassian.confluence.upgrade.UpgradeLauncherServletContextListener.contextInitialized(UpgradeLauncherServletContextListener.java:29)	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)	at org.apache.catalina.core.StandardService.start(StandardService.java:525)	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)	at java.lang.reflect.Method.invoke(Method.java:597)	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)2011-09-21 14:41:52,726 ERROR [main] [atlassian.confluence.upgrade.UpgradeLauncherServletContextListener] contextInitialized Upgrade failed, application will not start: com.atlassian.config.ConfigurationException: Cannot update schemacom.atlassian.confluence.upgrade.UpgradeException: com.atlassian.config.ConfigurationException: Cannot update schema	at com.atlassian.confluence.upgrade.AbstractUpgradeManager.upgrade(AbstractUpgradeManager.java:113)	at com.atlassian.confluence.upgrade.UpgradeLauncherServletContextListener.contextInitialized(UpgradeLauncherServletContextListener.java:29)	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)	at org.apache.catalina.core.StandardService.start(StandardService.java:525)	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)	at java.lang.reflect.Method.invoke(Method.java:597)	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)Caused by: com.atlassian.config.ConfigurationException: Cannot update schema	at bucket.core.persistence.hibernate.schema.SchemaHelper.updateSchemaIfNeeded(SchemaHelper.java:165)	at bucket.core.persistence.hibernate.schema.SchemaHelper.updateSchemaIfNeeded(SchemaHelper.java:134)	at com.atlassian.confluence.upgrade.AbstractUpgradeManager.upgrade(AbstractUpgradeManager.java:93)	... 16 moreCaused by: com.microsoft.sqlserver.jdbc.SQLServerException: Foreign key 'fk_app_dir_group_app' has implicit reference to object 'cwd_application' which does not have a primary key defined on it.	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:775)	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:633)	at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)	at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)	at net.sf.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:167)	at bucket.core.persistence.hibernate.schema.SchemaHelper.updateSchemaIfNeeded(SchemaHelper.java:161)	... 18 more2011-09-21 14:41:52,742 ERROR [main] [atlassian.confluence.upgrade.UpgradeLauncherServletContextListener] contextInitialized 1 errors were encountered during upgrade:2011-09-21 14:41:52,742 ERROR [main] [atlassian.confluence.upgrade.UpgradeLauncherServletContextListener] contextInitialized 1: Cannot update schema
```


Answers:
author: CharlesA
body: It looks like you're running into this issue: [Unable to Upgrade on SQL Server Due to 'Foreign key has implicit reference to object which does not have a primary key defined on it'](http://confluence.atlassian.com/display/CONFKB/Unable+to+Upgrade+on+SQL+Server+Due+to+%27Foreign+key+has+implicit+reference+to+object+which+does+not+have+a+primary+key+defined+on+it%27). The cause of this issue is missing foreign keys in your database. Often this is caused by restoring from an SQL Server db dump that did not contain foreign keys, but it could just be that Confluence somehow failed to add them.

If the steps listed on the linked page don't help you solve the issue, I'd recommend you open a support ticket on <http://support.atlassian.com> so a technician can walk you through fixing the problem.

comments: author: Aaron McClimont
body: Thank you, I have resolved this issue by exporting the content from Confluence 3.5.13 as an XML backup (including attachments), installing a clean install of Confluence 4, and using the XML backup as the restore archive during the setup process of Confluence 4.