koel / koel

🐦 A personal music streaming server that works.
https://koel.dev
MIT License
16.06k stars 1.98k forks source link

Migration failed because of a duplicate column name #1780

Open riyuatarashi opened 4 months ago

riyuatarashi commented 4 months ago

Describe the bug The migration forward 7.0 failed because of an already existing column name position on migration database/migrations/2024_01_27_171649_add_position_into_playlists_table.php

To reproduce Steps to reproduce the behavior:

  1. Create a new Koel server from 6.x
  2. Try to update to 7.x
  3. Migration failed
==> Initializing or migrating koel
************************************
*     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 ......................................................................................................................... 3ms DONE
  .env file exists -- skipping ................................................................................................................ DONE
  Retrieving app key ...................................................................................................................... 0ms DONE
  Using app key: base64:3GDdd3xI5.. ........................................................................................................... DONE
  Migrating database ..................................................................................................................... 10ms 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.

Expected behavior Migration to pass.

Environment

Additional context laravel.log

[2024-07-12 11:51:31] production.ERROR: PDOException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'position' in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:587
Stack trace:
#0 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(587): PDOStatement->execute()
#1 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(816): Illuminate\Database\Connection->Illuminate\Database\{closure}()
#2 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(783): Illuminate\Database\Connection->runQueryCallback()
#3 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(588): Illuminate\Database\Connection->run()
#4 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php(110): Illuminate\Database\Connection->statement()
#5 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(602): Illuminate\Database\Schema\Blueprint->build()
#6 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(444): Illuminate\Database\Schema\Builder->build()
#7 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(355): Illuminate\Database\Schema\Builder->table()
#8 /app/code/database/migrations/2024_01_27_171649_add_position_into_playlists_table.php(13): Illuminate\Support\Facades\Facade::__callStatic()
#9 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(493): Illuminate\Database\Migrations\Migration@anonymous->up()
#10 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(410): Illuminate\Database\Migrations\Migrator->runMethod()
#11 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(419): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#12 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(216): Illuminate\Database\Migrations\Migrator->runMigration()
#13 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(37): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#14 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(756): Illuminate\Console\View\Components\Task->render()
#15 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(216): Illuminate\Database\Migrations\Migrator->write()
#16 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(181): Illuminate\Database\Migrations\Migrator->runUp()
#17 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(124): Illuminate\Database\Migrations\Migrator->runPending()
#18 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(92): Illuminate\Database\Migrations\Migrator->run()
#19 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(633): Illuminate\Database\Console\Migrations\MigrateCommand->Illuminate\Database\Console\Migrations\{closure}()
#20 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(104): Illuminate\Database\Migrations\Migrator->usingConnection()
#21 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Database\Console\Migrations\MigrateCommand->handle()
#22 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#23 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#24 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#25 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#26 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#27 /app/code/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
#28 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\Component\Console\Command\Command->run()
#29 /app/code/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
#30 /app/code/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#31 /app/code/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#32 /app/code/vendor/laravel/framework/src/Illuminate/Console/Application.php(163): Symfony\Component\Console\Application->run()
#33 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(400): Illuminate\Console\Application->call()
#34 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(355): Illuminate\Foundation\Console\Kernel->call()
#35 /app/code/app/Console/Commands/InitCommand.php(273): Illuminate\Support\Facades\Facade::__callStatic()
#36 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(37): App\Console\Commands\InitCommand::App\Console\Commands\{closure}()
#37 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Factory.php(58): Illuminate\Console\View\Components\Task->render()
#38 /app/code/app/Console/Commands/InitCommand.php(274): Illuminate\Console\View\Components\Factory->__call()
#39 /app/code/app/Console/Commands/InitCommand.php(62): App\Console\Commands\InitCommand->migrateDatabase()
#40 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Console\Commands\InitCommand->handle()
#41 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#42 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#43 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#44 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#45 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#46 /app/code/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
#47 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\Component\Console\Command\Command->run()
#48 /app/code/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
#49 /app/code/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#50 /app/code/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#51 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\Component\Console\Application->run()
#52 /app/code/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#53 {main}

Next Illuminate\Database\QueryException: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'position' (Connection: mysql, SQL: alter table `playlist_song` add `position` int unsigned not null default '0') in /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:829
Stack trace:
#0 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(783): Illuminate\Database\Connection->runQueryCallback()
#1 /app/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php(588): Illuminate\Database\Connection->run()
#2 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php(110): Illuminate\Database\Connection->statement()
#3 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(602): Illuminate\Database\Schema\Blueprint->build()
#4 /app/code/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php(444): Illuminate\Database\Schema\Builder->build()
#5 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(355): Illuminate\Database\Schema\Builder->table()
#6 /app/code/database/migrations/2024_01_27_171649_add_position_into_playlists_table.php(13): Illuminate\Support\Facades\Facade::__callStatic()
#7 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(493): Illuminate\Database\Migrations\Migration@anonymous->up()
#8 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(410): Illuminate\Database\Migrations\Migrator->runMethod()
#9 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(419): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#10 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(216): Illuminate\Database\Migrations\Migrator->runMigration()
#11 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(37): Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}()
#12 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(756): Illuminate\Console\View\Components\Task->render()
#13 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(216): Illuminate\Database\Migrations\Migrator->write()
#14 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(181): Illuminate\Database\Migrations\Migrator->runUp()
#15 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(124): Illuminate\Database\Migrations\Migrator->runPending()
#16 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(92): Illuminate\Database\Migrations\Migrator->run()
#17 /app/code/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(633): Illuminate\Database\Console\Migrations\MigrateCommand->Illuminate\Database\Console\Migrations\{closure}()
#18 /app/code/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(104): Illuminate\Database\Migrations\Migrator->usingConnection()
#19 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Database\Console\Migrations\MigrateCommand->handle()
#20 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#21 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#22 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#23 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#24 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#25 /app/code/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
#26 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\Component\Console\Command\Command->run()
#27 /app/code/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
#28 /app/code/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#29 /app/code/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#30 /app/code/vendor/laravel/framework/src/Illuminate/Console/Application.php(163): Symfony\Component\Console\Application->run()
#31 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(400): Illuminate\Console\Application->call()
#32 /app/code/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(355): Illuminate\Foundation\Console\Kernel->call()
#33 /app/code/app/Console/Commands/InitCommand.php(273): Illuminate\Support\Facades\Facade::__callStatic()
#34 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php(37): App\Console\Commands\InitCommand::App\Console\Commands\{closure}()
#35 /app/code/vendor/laravel/framework/src/Illuminate/Console/View/Components/Factory.php(58): Illuminate\Console\View\Components\Task->render()
#36 /app/code/app/Console/Commands/InitCommand.php(274): Illuminate\Console\View\Components\Factory->__call()
#37 /app/code/app/Console/Commands/InitCommand.php(62): App\Console\Commands\InitCommand->migrateDatabase()
#38 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Console\Commands\InitCommand->handle()
#39 /app/code/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#40 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#41 /app/code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#42 /app/code/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
#43 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#44 /app/code/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
#45 /app/code/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\Component\Console\Command\Command->run()
#46 /app/code/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
#47 /app/code/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#48 /app/code/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#49 /app/code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\Component\Console\Application->run()
#50 /app/code/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#51 {main} 
phanan commented 4 months ago

This tends to happen if you have a problem with the migration and try to rerun it. Due to how databases work, actions like alter table can't be rolled back with transactions. In this case, the problem is likely as follows:

  1. A migration was attempted
  2. The column was created
  3. The migration errored out, but the column has already been created
  4. You reran the migration
  5. The column was created (again) <--- error

Because of this limitation, always run migration with a clean state.

In your case, have you tried upgrading to v7.0.2?