[GH-ISSUE #1975] [Bug]: Database migration issue with 7.6.3 #1050

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

Originally created by @nebulade on GitHub (Jun 28, 2025).
Original GitHub issue: https://github.com/koel/koel/issues/1975

Originally assigned to: @phanan on GitHub.

Read the Troubleshooting guide.

  • I have read and followed the Troubleshooting guide

Reproduction steps

  1. Fresh setup of koel 7.6.3
  2. Run /app/code/artisan koel:init --no-assets --no-interaction --no-scheduler
  3. Migration error

Expected behavior

Initial db migration/setup works

Actual behavior

Setup fails with:

************************************
*     KOEL INSTALLATION WIZARD     *
************************************

As a reminder, you can always install/upgrade manually following the guide at https://docs.koel.dev


   INFO  Running in no-interaction mode.  

  Clearing caches ...................................................................................................................... 4.14ms DONE
  .env file exists -- skipping ................................................................................................................ DONE
  Generating app key ................................................................................................................... 1.88ms DONE
  Using app key: base64:QENGdkvGp.. ........................................................................................................... DONE
  Migrating database .................................................................................................................. 14.41ms FAIL

   ERROR  Oops! Koel installation or upgrade didn't finish successfully.  

   ERROR  Please check the error log at storage/logs/laravel.log and try again.  

   ERROR  For further troubleshooting, visit https://docs.koel.dev/troubleshooting.  

   ERROR  😥 Sorry for this. You deserve better.  

root@4c7bdbf4-dfc2-4056-ab1d-88943b756f67:/app/code# cat storage/logs/laravel.log
[2025-06-27 11:26:18] production.ERROR: PDOException: SQLSTATE[HY000]: General error: 1832 Cannot change column 'organization_id': used in a foreign key constraint 'users_organization_id_foreign' in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:571

Logs

Stack trace:
#0 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(571): PDOStatement->execute()
#1 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(812): Illuminate\Database\Connection->Illuminate\Database\{closure}()
#2 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(779): Illuminate\Database\Connection->runQueryCallback()
#3 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(560): Illuminate\Database\Connection->run()
#4 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php(118): Illuminate\Database\Connection->statement()
#5 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(564): Illuminate\Database\Schema\Blueprint->build()
#6 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(406): Illuminate\Database\Schema\Builder->build()
#7 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(361): Illuminate\Database\Schema\Builder->table()
#8 /app/code/database/migrations/2025_06_16_141017_create_organizations_table.php(35): Illuminate\Support\Facades\Facade::__callStatic()
#9 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(507): Illuminate\Database\Migrations\Migration@anonymous->up()
#10 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(432): Illuminate\Database\Migrations\Migrator->runMethod()
#11 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(441): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#12 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(244): Illuminate\Database\Migrations\Migrator->runMigration()
#13 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(40): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#14 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(798): Illuminate\Console\View\Components\Task->render()
#15 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(244): Illuminate\Database\Migrations\Migrator->write()
#16 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(211): Illuminate\Database\Migrations\Migrator->runUp()
#17 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(138): Illuminate\Database\Migrations\Migrator->runPending()
#18 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(117): Illuminate\Database\Migrations\Migrator->run()
#19 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(658): Illuminate\Database\Console\Migrations\MigrateCommand->Illuminate\Database\Console\Migrations\{closure}()
#20 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(110): Illuminate\Database\Migrations\Migrator->usingConnection()
#21 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(89): Illuminate\Database\Console\Migrations\MigrateCommand->runMigrations()
#22 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Database\Console\Migrations\MigrateCommand->handle()
#23 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#24 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\Container\Util::unwrapIfClosure()
#25 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#26 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(696): Illuminate\Container\BoundMethod::call()
#27 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\Container\Container->call()
#28 /app/code/vendor/symfony/console/Command/Command.php(318): Illuminate\Console\Command->execute()
#29 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\Component\Console\Command\Command->run()
#30 /app/code/vendor/symfony/console/Application.php(1092): Illuminate\Console\Command->run()
#31 /app/code/vendor/symfony/console/Application.php(341): Symfony\Component\Console\Application->doRunCommand()
#32 /app/code/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRun()
#33 /app/code/vendor/laravel/framework/src/Illuminate/Console/Application.php(166): Symfony\Component\Console\Application->run()
#34 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(427): Illuminate\Console\Application->call()
#35 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(361): Illuminate\Foundation\Console\Kernel->call()
#36 /app/code/app/Console/Commands/InitCommand.php(262): Illuminate\Support\Facades\Facade::__callStatic()
#37 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(40): App\Console\Commands\InitCommand::App\Console\Commands\{closure}()
#38 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Factory.php(60): Illuminate\Console\View\Components\Task->render()
#39 /app/code/app/Console/Commands/InitCommand.php(261): Illuminate\Console\View\Components\Factory->__call()
#40 /app/code/app/Console/Commands/InitCommand.php(56): App\Console\Commands\InitCommand->migrateDatabase()
#41 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Console\Commands\InitCommand->handle()
#42 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#43 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\Container\Util::unwrapIfClosure()
#44 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#45 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(696): Illuminate\Container\BoundMethod::call()
#46 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\Container\Container->call()
#47 /app/code/vendor/symfony/console/Command/Command.php(318): Illuminate\Console\Command->execute()
#48 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\Component\Console\Command\Command->run()
#49 /app/code/vendor/symfony/console/Application.php(1092): Illuminate\Console\Command->run()
#50 /app/code/vendor/symfony/console/Application.php(341): Symfony\Component\Console\Application->doRunCommand()
#51 /app/code/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRun()
#52 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(198): Symfony\Component\Console\Application->run()
#53 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1235): Illuminate\Foundation\Console\Kernel->handle()
#54 /app/code/artisan(16): Illuminate\Foundation\Application->handleCommand()
#55 {main}

Koel version

7.6.3

How did you install Koel?

Compiled from source

Additional information

  • Server OS: Cloudron
  • PHP version: 8.3
  • Database: mysql
  • Node version: 22.14.0
  • Browser & device: firefox
Originally created by @nebulade on GitHub (Jun 28, 2025). Original GitHub issue: https://github.com/koel/koel/issues/1975 Originally assigned to: @phanan on GitHub. ### Read the Troubleshooting guide. - [x] I have read and followed the Troubleshooting guide ### Reproduction steps 1. Fresh setup of koel 7.6.3 2. Run /app/code/artisan koel:init --no-assets --no-interaction --no-scheduler 3. Migration error ### Expected behavior Initial db migration/setup works ### Actual behavior Setup fails with: ``` ************************************ * KOEL INSTALLATION WIZARD * ************************************ As a reminder, you can always install/upgrade manually following the guide at https://docs.koel.dev INFO Running in no-interaction mode. Clearing caches ...................................................................................................................... 4.14ms DONE .env file exists -- skipping ................................................................................................................ DONE Generating app key ................................................................................................................... 1.88ms DONE Using app key: base64:QENGdkvGp.. ........................................................................................................... DONE Migrating database .................................................................................................................. 14.41ms FAIL ERROR Oops! Koel installation or upgrade didn't finish successfully. ERROR Please check the error log at storage/logs/laravel.log and try again. ERROR For further troubleshooting, visit https://docs.koel.dev/troubleshooting. ERROR 😥 Sorry for this. You deserve better. root@4c7bdbf4-dfc2-4056-ab1d-88943b756f67:/app/code# cat storage/logs/laravel.log [2025-06-27 11:26:18] production.ERROR: PDOException: SQLSTATE[HY000]: General error: 1832 Cannot change column 'organization_id': used in a foreign key constraint 'users_organization_id_foreign' in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:571 ``` ### Logs ``` Stack trace: #0 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(571): PDOStatement->execute() #1 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(812): Illuminate\Database\Connection->Illuminate\Database\{closure}() #2 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(779): Illuminate\Database\Connection->runQueryCallback() #3 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(560): Illuminate\Database\Connection->run() #4 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php(118): Illuminate\Database\Connection->statement() #5 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(564): Illuminate\Database\Schema\Blueprint->build() #6 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(406): Illuminate\Database\Schema\Builder->build() #7 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(361): Illuminate\Database\Schema\Builder->table() #8 /app/code/database/migrations/2025_06_16_141017_create_organizations_table.php(35): Illuminate\Support\Facades\Facade::__callStatic() #9 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(507): Illuminate\Database\Migrations\Migration@anonymous->up() #10 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(432): Illuminate\Database\Migrations\Migrator->runMethod() #11 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(441): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}() #12 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(244): Illuminate\Database\Migrations\Migrator->runMigration() #13 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(40): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}() #14 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(798): Illuminate\Console\View\Components\Task->render() #15 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(244): Illuminate\Database\Migrations\Migrator->write() #16 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(211): Illuminate\Database\Migrations\Migrator->runUp() #17 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(138): Illuminate\Database\Migrations\Migrator->runPending() #18 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(117): Illuminate\Database\Migrations\Migrator->run() #19 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(658): Illuminate\Database\Console\Migrations\MigrateCommand->Illuminate\Database\Console\Migrations\{closure}() #20 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(110): Illuminate\Database\Migrations\Migrator->usingConnection() #21 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(89): Illuminate\Database\Console\Migrations\MigrateCommand->runMigrations() #22 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Database\Console\Migrations\MigrateCommand->handle() #23 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #24 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\Container\Util::unwrapIfClosure() #25 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod() #26 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(696): Illuminate\Container\BoundMethod::call() #27 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\Container\Container->call() #28 /app/code/vendor/symfony/console/Command/Command.php(318): Illuminate\Console\Command->execute() #29 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\Component\Console\Command\Command->run() #30 /app/code/vendor/symfony/console/Application.php(1092): Illuminate\Console\Command->run() #31 /app/code/vendor/symfony/console/Application.php(341): Symfony\Component\Console\Application->doRunCommand() #32 /app/code/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRun() #33 /app/code/vendor/laravel/framework/src/Illuminate/Console/Application.php(166): Symfony\Component\Console\Application->run() #34 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(427): Illuminate\Console\Application->call() #35 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(361): Illuminate\Foundation\Console\Kernel->call() #36 /app/code/app/Console/Commands/InitCommand.php(262): Illuminate\Support\Facades\Facade::__callStatic() #37 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(40): App\Console\Commands\InitCommand::App\Console\Commands\{closure}() #38 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Factory.php(60): Illuminate\Console\View\Components\Task->render() #39 /app/code/app/Console/Commands/InitCommand.php(261): Illuminate\Console\View\Components\Factory->__call() #40 /app/code/app/Console/Commands/InitCommand.php(56): App\Console\Commands\InitCommand->migrateDatabase() #41 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Console\Commands\InitCommand->handle() #42 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #43 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\Container\Util::unwrapIfClosure() #44 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod() #45 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(696): Illuminate\Container\BoundMethod::call() #46 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\Container\Container->call() #47 /app/code/vendor/symfony/console/Command/Command.php(318): Illuminate\Console\Command->execute() #48 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\Component\Console\Command\Command->run() #49 /app/code/vendor/symfony/console/Application.php(1092): Illuminate\Console\Command->run() #50 /app/code/vendor/symfony/console/Application.php(341): Symfony\Component\Console\Application->doRunCommand() #51 /app/code/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRun() #52 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(198): Symfony\Component\Console\Application->run() #53 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1235): Illuminate\Foundation\Console\Kernel->handle() #54 /app/code/artisan(16): Illuminate\Foundation\Application->handleCommand() #55 {main} ``` ### Koel version 7.6.3 ### How did you install Koel? Compiled from source ### Additional information - **Server OS**: Cloudron - **PHP version**: 8.3 - **Database**: mysql - **Node version**: 22.14.0 - **Browser & device**: firefox
kerem closed this issue 2026-02-26 02:35:05 +03:00
Author
Owner

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

What’s the db version?

On Sat, Jun 28, 2025 at 14:28 Johannes Zellner @.***>
wrote:

Assigned #1975 https://github.com/koel/koel/issues/1975 to @phanan
https://github.com/phanan.


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

<!-- gh-comment-id:3015071734 --> @phanan commented on GitHub (Jun 28, 2025): What’s the db version? On Sat, Jun 28, 2025 at 14:28 Johannes Zellner ***@***.***> wrote: > Assigned #1975 <https://github.com/koel/koel/issues/1975> to @phanan > <https://github.com/phanan>. > > — > Reply to this email directly, view it on GitHub > <https://github.com/koel/koel/issues/1975#event-18367689419>, or > unsubscribe > <https://github.com/notifications/unsubscribe-auth/AB5O3URB5UE4MNP25RUJQ2D3FY7ZDAVCNFSM6AAAAACAKTC3Y2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJYGM3DONRYHE2DCOI> > . > You are receiving this because you were assigned.Message ID: > ***@***.***> >
Author
Owner

@nebulade commented on GitHub (Jun 28, 2025):

Sorry for late answer, will debug later today a bit, just wanted it to be logged here already.

The MySql version is Ver 8.0.41-0ubuntu0.24.04.1 for Linux on x86_64 ((Ubuntu))

Otherwise this is from an empty database, in case you asked for the migration step at which the script starts with.

<!-- gh-comment-id:3015242186 --> @nebulade commented on GitHub (Jun 28, 2025): Sorry for late answer, will debug later today a bit, just wanted it to be logged here already. The MySql version is `Ver 8.0.41-0ubuntu0.24.04.1 for Linux on x86_64 ((Ubuntu))` Otherwise this is from an empty database, in case you asked for the migration step at which the script starts with.
Author
Owner

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

Otherwise this is from an empty database, in case you asked for the migration step at which the script starts with.

This is curious then 🤔 . The CI uses MariaDB (should be compatible with MySQL, at least for these stuff) on a blank state of course, and it didn't report this error.

<!-- gh-comment-id:3015262786 --> @phanan commented on GitHub (Jun 28, 2025): > Otherwise this is from an empty database, in case you asked for the migration step at which the script starts with. This is curious then 🤔 . The CI uses MariaDB (should be compatible with MySQL, at least for these stuff) on a blank state of course, and it didn't report this error.
Author
Owner

@nebulade commented on GitHub (Jun 28, 2025):

I managed to look into this a bit, although I am not a laravel expert. So commenting out the failing line at github.com/koel/koel@befb8a33ed/database/migrations/2025_06_16_141017_create_organizations_table.php (L36) obviously makes it work. Now if I interpret that migration script correctly, it first creates the column with allowing null values, then creates the foreign key and then tries to adjust the column to not allow null values (which is failing).

Presumably DB::table('users')->update(['organization_id' => Organization::default()->id]); in-between will somehow set the column for existing rows (where null) to some default value, which then allows for it to be non-null from here on. Apparently mysql then unlike mariadb does not allow column schema changes after used in foreign keys this way. Is there a way in laravel to reorder this and only setup the foreign key after setting initial values? Question might sound stupid, but I am not quite sure what that line above does.

<!-- gh-comment-id:3015560897 --> @nebulade commented on GitHub (Jun 28, 2025): I managed to look into this a bit, although I am not a laravel expert. So commenting out the failing line at https://github.com/koel/koel/blob/befb8a33ed662994730be895f77995f9b6132090/database/migrations/2025_06_16_141017_create_organizations_table.php#L36 obviously makes it work. Now if I interpret that migration script correctly, it first creates the column with allowing null values, then creates the foreign key and then tries to adjust the column to not allow null values (which is failing). Presumably `DB::table('users')->update(['organization_id' => Organization::default()->id]);` in-between will somehow set the column for existing rows (where null) to some default value, which then allows for it to be non-null from here on. Apparently mysql then unlike mariadb does not allow column schema changes after used in foreign keys this way. Is there a way in laravel to reorder this and only setup the foreign key after setting initial values? Question might sound stupid, but I am not quite sure what that line above does.
Author
Owner

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

Thanks for the details. I think instead of adding the foreign key/index, setting the value, and then trying to modify it, we can just move the foreign key/index creation to after setting the value. This way, forcing users.organization_id to NOT NULL shouldn't clash with any index. WDYT?

<!-- gh-comment-id:3015592958 --> @phanan commented on GitHub (Jun 28, 2025): Thanks for the details. I think instead of adding the foreign key/index, setting the value, and then trying to modify it, we can just move the foreign key/index creation to _after_ setting the value. This way, forcing `users.organization_id` to NOT NULL shouldn't clash with any index. WDYT?
Author
Owner

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

Something like this:

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('organizations', static function (Blueprint $table): void {
            $table->string('id', 26)->primary();
            $table->string('name');
            $table->string('slug')->unique();
            $table->timestamps();
        });

        Schema::table('users', static function (Blueprint $table): void {
            $table->string('organization_id', 26)->nullable()->after('id')->index();
        });

        DB::table('users')->update(['organization_id' => Organization::default()->id]);

        Schema::table('users', static function (Blueprint $table): void {
            $table->string('organization_id', 26)->nullable(false)->change();

            $table->foreign('organization_id')
                ->references('id')
                ->on('organizations')
                ->cascadeOnDelete()
                ->cascadeOnUpdate();
        });
    }
};

Do you think you can try this out and let me know if it works?

<!-- gh-comment-id:3015596944 --> @phanan commented on GitHub (Jun 28, 2025): Something like this: ```php return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('organizations', static function (Blueprint $table): void { $table->string('id', 26)->primary(); $table->string('name'); $table->string('slug')->unique(); $table->timestamps(); }); Schema::table('users', static function (Blueprint $table): void { $table->string('organization_id', 26)->nullable()->after('id')->index(); }); DB::table('users')->update(['organization_id' => Organization::default()->id]); Schema::table('users', static function (Blueprint $table): void { $table->string('organization_id', 26)->nullable(false)->change(); $table->foreign('organization_id') ->references('id') ->on('organizations') ->cascadeOnDelete() ->cascadeOnUpdate(); }); } }; ``` Do you think you can try this out and let me know if it works?
Author
Owner

@nebulade commented on GitHub (Jun 28, 2025):

ah same idea/solution then (see PR). Yes that worked fine for me

<!-- gh-comment-id:3015602980 --> @nebulade commented on GitHub (Jun 28, 2025): ah same idea/solution then (see PR). Yes that worked fine for me
Author
Owner

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

That's super fast! Thank you. Let's wait for the CI and I'll merge it.

<!-- gh-comment-id:3015608221 --> @phanan commented on GitHub (Jun 28, 2025): That's super fast! Thank you. Let's wait for the CI and I'll merge it.
Author
Owner

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

ICYMI, I've tagged a new version that includes this fix. Thanks again for the great help!
P.S. Cloudron looks super dope!

<!-- gh-comment-id:3015895690 --> @phanan commented on GitHub (Jun 28, 2025): ICYMI, I've tagged a [new version](https://github.com/koel/koel/releases/tag/v7.7.0) that includes this fix. Thanks again for the great help! P.S. Cloudron looks super dope!
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#1050
No description provided.