Bitbucket Server Upgrade to 2.4.0 Fails with "Specified key was too long" Exception

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

The following exception is reported when upgrading Bitbucket Server to 2.4.x

1 2 3 4 5 6 7 8 9 10 11 2013-05-07 16:38:30,539 INFO [localhost-startStop-1] c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory /home/www/data/bitbucket/instance for 158926@STASHSERVER 2013-05-07 16:38:34,276 ERROR [localhost-startStop-1] liquibase Change Set liquibase/r2_4/upgrade.xml::BSERVDEV-3734-4::mstudman failed. Error: Error executing SQL ALTER TABLE `bitbucket`.`bitbucket_user` ADD CONSTRAINT `uq_bitbucket_user_slug` UNIQUE (`slug`): Specified key was too long; max key length is 767 bytes liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE `bitbucket`.`bitbucket_user` ADD CONSTRAINT `uq_bitbucket_user_slug` UNIQUE (`slug`): Specified key was too long; max key length is 767 bytes at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62) ~[liquibase-core-2.0.5.jar:na] at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104) ~[liquibase-core-2.0.5.jar:na] at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1091) ~[liquibase-core-2.0.5.jar:na] at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1075) ~[liquibase-core-2.0.5.jar:na] at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317) ~[liquibase-core-2.0.5.jar:na] at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27) [liquibase-core-2.0.5.jar:na] at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58) [liquibase-core-2.0.5.jar:na] at liquibase.Liquibase.update(Liquibase.java:114) [liquibase-core-2.0.5.jar:na]

Further Troubleshooting

Use a database viewer, such as DBVisualizer to connect to your current Bitbucket Server database and run the following query:

1 run desc bitbucket_user;

This will give an output similar to:

1 2 3 4 5 6 7 8 9 mysql> desc bitbucket_user; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(255) | NO | UNI | NULL | | | slug | varchar(255) | NO | | NULL | | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)

This will help confirm the table schema for 'bitbucket_user' table.

Cause

If the result of the above query does not match the expected result above but is instead:

1 2 3 4 5 6 7 8 9 mysql> desc bitbucket_user; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(255) | NO | UNI | NULL | | | slug | varchar(766) | NO | UNI | NULL | | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)

it indicates that the above schema is from the Bitbucket Server 2.4 beta, not the final official release. This can happen if Bitbucket Server was upgraded to the 2.4 beta (or attempted to) and then to 2.4 stable release.The schema in 2.4.0 and 2.4.1 is 255 characters for slug - only the beta release used 766.

The Bitbucket Server upgrade task wasn't designed to upgrade from the beta to a final release, so it will take some manual SQL to help resolve it.

Resolution

Run the following query on your Bitbucket Server database:

1 UPDATE DATABASECHANGELOG SET ID = 'BSERVDEV-3734-4', MD5SUM = '3:0915ae71248292c6cc8c73d79b6a5cc4' WHERE ID = 'BSERVDEV-3734-5';

and restart Bitbucket Server to complete the upgrade.

Updated on April 11, 2025

Still need help?

The Atlassian Community is here for you.