Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback command doesn't work #2342

Open
arodu opened this issue Feb 7, 2025 · 2 comments
Open

Rollback command doesn't work #2342

arodu opened this issue Feb 7, 2025 · 2 comments

Comments

@arodu
Copy link

arodu commented Feb 7, 2025

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!

@dereuromark
Copy link
Member

You might also want to share the relevant migration file content

@arodu
Copy link
Author

arodu commented Feb 7, 2025

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();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants