[GH-ISSUE #1969] [Bug]: MySQL migration issue with 7.6.x #1046

Closed
opened 2026-02-26 02:35:04 +03:00 by kerem · 6 comments
Owner

Originally created by @gramakri on GitHub (Jun 24, 2025).
Original GitHub issue: https://github.com/koel/koel/issues/1969

Originally assigned to: @phanan on GitHub.

Read the Troubleshooting guide.

  • I have read and followed the Troubleshooting guide

Reproduction steps

  1. Run /app/code/artisan koel:init --no-assets --no-interaction --no-scheduler
  2. Migration error

Expected behavior

Migration/init should not error

Actual behavior

Migration errors

Logs

Error from the logs:

[2025-06-24 09:50:24] production.ERROR: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:571
Stack trace:

Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table `artists` add unique `artists_name_user_id_unique`(`name`, `user_id`)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825

Koel version

7.6.2

How did you install Koel?

Compiled from source

Additional information

  • Server OS: Cloudron
  • PHP version: 8.3
  • Database: MySQL
  • Node version: v22.14.0
  • Browser & device: Firefox
Originally created by @gramakri on GitHub (Jun 24, 2025). Original GitHub issue: https://github.com/koel/koel/issues/1969 Originally assigned to: @phanan on GitHub. ### Read the Troubleshooting guide. - [x] I have read and followed the Troubleshooting guide ### Reproduction steps 1. Run `/app/code/artisan koel:init --no-assets --no-interaction --no-scheduler` 2. Migration error ### Expected behavior Migration/init should not error ### Actual behavior Migration errors ### Logs Error from the logs: ``` [2025-06-24 09:50:24] production.ERROR: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:571 Stack trace: Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table `artists` add unique `artists_name_user_id_unique`(`name`, `user_id`)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825 ``` ### Koel version 7.6.2 ### How did you install Koel? Compiled from source ### Additional information - **Server OS**: Cloudron - **PHP version**: 8.3 - **Database**: MySQL - **Node version**: v22.14.0 - **Browser & device**: Firefox
kerem closed this issue 2026-02-26 02:35:04 +03:00
Author
Owner

@gramakri commented on GitHub (Jun 24, 2025):

The issue seems to come from 2025_06_12_150202_user-scope_artists_and_albums.php . There the code adds a unique constraint for the name column at https://github.com/koel/koel/blob/master/database/migrations/2025_06_12_150202_user-scope_artists_and_albums.php#L21

The MySQL table schema is like this:

| artists | CREATE TABLE `artists` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `image` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `public_id` varchar(26) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_id` int unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `artists_user_id_foreign` (`user_id`),
  CONSTRAINT `artists_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |

MySQL does not allow indexes (including composite UNIQUE indexes) directly on TEXT/BLOB columns without explicitly specifying a prefix length.

See also https://stackoverflow.com/questions/14033378/make-text-column-as-unique-key

<!-- gh-comment-id:2999659681 --> @gramakri commented on GitHub (Jun 24, 2025): The issue seems to come from `2025_06_12_150202_user-scope_artists_and_albums.php` . There the code adds a unique constraint for the `name` column at https://github.com/koel/koel/blob/master/database/migrations/2025_06_12_150202_user-scope_artists_and_albums.php#L21 The MySQL table schema is like this: ``` | artists | CREATE TABLE `artists` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `name` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, `image` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `public_id` varchar(26) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `user_id` int unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `artists_user_id_foreign` (`user_id`), CONSTRAINT `artists_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci | ``` MySQL does not allow indexes (including composite UNIQUE indexes) directly on TEXT/BLOB columns without explicitly specifying a prefix length. See also https://stackoverflow.com/questions/14033378/make-text-column-as-unique-key
Author
Owner

@phanan commented on GitHub (Jun 24, 2025):

Can you try removing the index creation code and see if the migration goes
though? If yes I issue a fix. Interestingly the CI didn’t catch this.

On Tue, Jun 24, 2025 at 12:08 Girish Ramakrishnan @.***>
wrote:

gramakri left a comment (koel/koel#1969)
https://github.com/koel/koel/issues/1969#issuecomment-2999659681

The issue seems to come from
2025_06_12_150202_user-scope_artists_and_albums.php . There the code adds
a unique constraint for the name column at
https://github.com/koel/koel/blob/master/database/migrations/2025_06_12_150202_user-scope_artists_and_albums.php#L21

The MySQL table schema is like this:

| artists | CREATE TABLE artists (
id int unsigned NOT NULL AUTO_INCREMENT,
name mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
image varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
created_at timestamp NULL DEFAULT NULL,
updated_at timestamp NULL DEFAULT NULL,
public_id varchar(26) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
user_id int unsigned DEFAULT NULL,
PRIMARY KEY (id),
KEY artists_user_id_foreign (user_id),
CONSTRAINT artists_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |

MySQL does not allow indexes (including composite UNIQUE indexes) directly
on TEXT/BLOB columns without explicitly specifying a prefix length.

See also
https://stackoverflow.com/questions/14033378/make-text-column-as-unique-key


Reply to this email directly, view it on GitHub
https://github.com/koel/koel/issues/1969#issuecomment-2999659681, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AB5O3UTK75HPZPPXRDAESOL3FEPRVAVCNFSM6AAAAAB772HNGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJZGY2TSNRYGE
.
You are receiving this because you were assigned.Message ID:
@.***>

<!-- gh-comment-id:2999713209 --> @phanan commented on GitHub (Jun 24, 2025): Can you try removing the index creation code and see if the migration goes though? If yes I issue a fix. Interestingly the CI didn’t catch this. On Tue, Jun 24, 2025 at 12:08 Girish Ramakrishnan ***@***.***> wrote: > *gramakri* left a comment (koel/koel#1969) > <https://github.com/koel/koel/issues/1969#issuecomment-2999659681> > > The issue seems to come from > 2025_06_12_150202_user-scope_artists_and_albums.php . There the code adds > a unique constraint for the name column at > https://github.com/koel/koel/blob/master/database/migrations/2025_06_12_150202_user-scope_artists_and_albums.php#L21 > > The MySQL table schema is like this: > > | artists | CREATE TABLE `artists` ( > `id` int unsigned NOT NULL AUTO_INCREMENT, > `name` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL, > `image` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, > `created_at` timestamp NULL DEFAULT NULL, > `updated_at` timestamp NULL DEFAULT NULL, > `public_id` varchar(26) COLLATE utf8mb4_unicode_ci DEFAULT NULL, > `user_id` int unsigned DEFAULT NULL, > PRIMARY KEY (`id`), > KEY `artists_user_id_foreign` (`user_id`), > CONSTRAINT `artists_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci | > > > MySQL does not allow indexes (including composite UNIQUE indexes) directly > on TEXT/BLOB columns without explicitly specifying a prefix length. > > See also > https://stackoverflow.com/questions/14033378/make-text-column-as-unique-key > > — > Reply to this email directly, view it on GitHub > <https://github.com/koel/koel/issues/1969#issuecomment-2999659681>, or > unsubscribe > <https://github.com/notifications/unsubscribe-auth/AB5O3UTK75HPZPPXRDAESOL3FEPRVAVCNFSM6AAAAAB772HNGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJZGY2TSNRYGE> > . > You are receiving this because you were assigned.Message ID: > ***@***.***> >
Author
Owner

@gramakri commented on GitHub (Jun 24, 2025):

Was debugging this a bit. In 2021_12_06_164648_increase_string_columns_length.php , the name column length changed to 65504 . The default database encoding in Cloudron is utf8mb4 . In mysql, VARCHAR is max 65536 bytes and with utf8mb4, VARCHAR can only hold 16384 characters . After this, it will get upped into a TEXT field . This is why name became a MEDIUMTEXT in the first place.

@phanan in the CI, do you know the database encoding? What encoding is suggested by koel?

<!-- gh-comment-id:3000931457 --> @gramakri commented on GitHub (Jun 24, 2025): Was debugging this a bit. In `2021_12_06_164648_increase_string_columns_length.php` , the name column length changed to 65504 . The default database encoding in Cloudron is `utf8mb4` . In mysql, VARCHAR is max 65536 bytes and with utf8mb4, VARCHAR can only hold 16384 characters . After this, it will get upped into a TEXT field . This is why `name` became a MEDIUMTEXT in the first place. @phanan in the CI, do you know the database encoding? What encoding is suggested by koel?
Author
Owner

@gramakri commented on GitHub (Jun 24, 2025):

Well, nevermind. It seems in config/database.php , mysql-ci is using utf8mb4 . Hmm...

I tried removing the 'name' as unique key (in both the tables in that migration field). Now that migration succeeds. But we have a new failure

Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table `albums` add unique `albums_name_artist_id_user_id_unique`(`name`, `artist_id`, `user_id`)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825
<!-- gh-comment-id:3000937010 --> @gramakri commented on GitHub (Jun 24, 2025): Well, nevermind. It seems in config/database.php , mysql-ci is using utf8mb4 . Hmm... I tried removing the 'name' as unique key (in both the tables in that migration field). Now that migration succeeds. But we have a new failure ``` Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table `albums` add unique `albums_name_artist_id_user_id_unique`(`name`, `artist_id`, `user_id`)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825 ```
Author
Owner

@phanan commented on GitHub (Jun 24, 2025):

That’s understandable, as the change applied to both artists and albums
tables. We can try to apply a length to the TEXT index, or remove the index
altogether.

On Tue, Jun 24, 2025 at 22:20 Girish Ramakrishnan @.***>
wrote:

gramakri left a comment (koel/koel#1969)
https://github.com/koel/koel/issues/1969#issuecomment-3000937010

Well, nevermind. It seems in config/database.php , mysql-ci is using
utf8mb4 . Hmm...

I tried removing the 'name' as unique key (in both the tables in that
migration field). Now that migration succeeds. But we have a new failure

Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table albums add unique albums_name_artist_id_user_id_unique(name, artist_id, user_id)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825


Reply to this email directly, view it on GitHub
https://github.com/koel/koel/issues/1969#issuecomment-3000937010, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AB5O3UVE7ZIGT63VBS3PCJ33FFUEHAVCNFSM6AAAAAB772HNGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBQHEZTOMBRGA
.
You are receiving this because you were mentioned.Message ID:
@.***>

<!-- gh-comment-id:3002079889 --> @phanan commented on GitHub (Jun 24, 2025): That’s understandable, as the change applied to both artists and albums tables. We can try to apply a length to the TEXT index, or remove the index altogether. On Tue, Jun 24, 2025 at 22:20 Girish Ramakrishnan ***@***.***> wrote: > *gramakri* left a comment (koel/koel#1969) > <https://github.com/koel/koel/issues/1969#issuecomment-3000937010> > > Well, nevermind. It seems in config/database.php , mysql-ci is using > utf8mb4 . Hmm... > > I tried removing the 'name' as unique key (in both the tables in that > migration field). Now that migration succeeds. But we have a new failure > > Next Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'name' used in key specification without a key length (Connection: mysql, SQL: alter table `albums` add unique `albums_name_artist_id_user_id_unique`(`name`, `artist_id`, `user_id`)) in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825 > > — > Reply to this email directly, view it on GitHub > <https://github.com/koel/koel/issues/1969#issuecomment-3000937010>, or > unsubscribe > <https://github.com/notifications/unsubscribe-auth/AB5O3UVE7ZIGT63VBS3PCJ33FFUEHAVCNFSM6AAAAAB772HNGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBQHEZTOMBRGA> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Author
Owner

@phanan commented on GitHub (Jun 25, 2025):

Fixed and released.

<!-- gh-comment-id:3003720461 --> @phanan commented on GitHub (Jun 25, 2025): Fixed and released.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/koel-koel#1046
No description provided.