cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.46k stars 892 forks source link

Argument #2 ($version) must be of type ?int, string given #2231

Closed kolorafa closed 10 months ago

kolorafa commented 11 months ago

./bin/cake migrations migrate -t 20231019152508

TypeError: Phinx\Migration\Manager::migrate(): Argument #2 ($version) must be of type ?int, string given, called in /app/vendor/robmorgan/phinx/src/Phinx/Console/Command/Migrate.php on line 124 and defined in /app/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php:312
Stack trace:
#0 /app/vendor/robmorgan/phinx/src/Phinx/Console/Command/Migrate.php(124): Phinx\Migration\Manager->migrate('default', '20231019152508', false)
#1 /app/vendor/cakephp/migrations/src/Command/Phinx/CommandTrait.php(37): Phinx\Console\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /app/vendor/cakephp/migrations/src/Command/Phinx/Migrate.php(88): Migrations\Command\Phinx\Migrate->parentExecute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /app/vendor/symfony/console/Command/Command.php(326): Migrations\Command\Phinx\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /app/vendor/symfony/console/Application.php(1063): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /app/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand(Object(Migrations\Command\Phinx\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /app/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /app/vendor/cakephp/migrations/src/Command/MigrationsCommand.php(127): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /app/vendor/cakephp/cakephp/src/Console/BaseCommand.php(192): Migrations\Command\MigrationsCommand->execute(Object(Cake\Console\Arguments), Object(Cake\Console\ConsoleIo))
#9 /app/vendor/cakephp/migrations/src/Command/MigrationsCommand.php(199): Cake\Console\BaseCommand->run(Array, Object(Cake\Console\ConsoleIo))
#10 /app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(327): Migrations\Command\MigrationsCommand->run(Array, Object(Cake\Console\ConsoleIo))
#11 /app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(168): Cake\Console\CommandRunner->runCommand(Object(Migrations\Command\MigrationsMigrateCommand), Array, Object(Cake\Console\ConsoleIo))
#12 /app/bin/cake.php(10): Cake\Console\CommandRunner->run(Array)
#13 {main}
BBBUlmer commented 10 months ago

+1 Same here, when using with robmorgan/phinx

What I did: removed composer.lock and did a fresh new composer install which in return resulted in "robmorgan/phinx" version 0.15.2 being installed.

The error remained when running vendor/bin/phinx rollback -t 0.


Update: I am sorry for possibly causing confusion. The error was solved on our side, as we actually did not use vendor/bin/phinx rollback -t 0 but rather vendor/bin/phinx migrate -t {existing migration number} which does not work.

When using the correct -d parameter it works fine. It seems that the -d option should be used when migrating down instead of the -t which fails if the migration version was already migrated.

The docs on migrate tell this:

 The migrate command runs all available migrations, optionally up to a specific version

  phinx migrate -e development
  phinx migrate -e development -t 20110103081132
  phinx migrate -e development -d 20110103
  phinx migrate -e development -v
wallacio commented 10 months ago

You haven't "solved" anything as such - you've found a genuine bug. I've opened a more detailed issue at https://github.com/cakephp/phinx/issues/2240.

dereuromark commented 10 months ago

Solved and merged, thx @wallacio