phinx
phinx copied to clipboard
Rollback command doesn't work
Hi team,
I encountered an issue using CakePHP 5.1.5. I created a new project and ran bin/cake migrations rollback, but the command fails with the following error:
/var/www/html$ bin/cake migrations rollback
using connection default
using paths /var/www/html/config/Migrations
ordering by creation time
== 20250129221158 CreateSchedules: reverting
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'schedules' already exists
Query: CREATE TABLE `schedules` (`id` INT(11) NOT NULL AUTO_INCREMENT, `section_id` INT(11) NOT NULL, `subject_block_id` INT(11) NOT NULL, `classroom_id` INT(11) NOT NULL, `day_pos` INT(11) NOT NULL, `time_pos` INT(11) NOT NULL, `locked` TINYINT(1) NOT NULL DEFAULT 0, `created` DATETIME NOT NULL, `modified` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
The project is new, and I haven't done anything differently compared to previous projects. Has anyone seen this issue before or have any suggestions?
Thanks in advance for your help!
You might also want to share the relevant migration file content
I created the migration with bake
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class CreateSchedules extends BaseMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('schedules');
$table->addColumn('section_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('subject_block_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('classroom_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('day_pos', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('time_pos', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('locked', 'boolean', [
'default' => false,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
This must be some kind of glitch, did you try using the latest version?
@dereuromark You're right, I didn't get this error again. I'm going to close this issue.. ty