migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Rollback throws exception after it runs.

Open sdustinh opened this issue 8 years ago • 7 comments

This is a (multiple allowed):

  • [x] bug
  • [ ] enhancement
  • [ ] feature-discussion (RFC)
sdustinh@claudia:~/github/app$ composer show cakephp/*
cakephp/bake                1.2.5              Bake plugin for CakePHP...
cakephp/cakephp             3.2.12             The CakePHP framework
cakephp/cakephp-codesniffer dev-master fe95558 CakePHP CodeSniffer Sta...
cakephp/chronos             0.4.11             A simple API extension ...
cakephp/debug_kit           3.2.9              CakePHP Debug Kit
cakephp/migrations          1.6.3              Database Migration plug...
cakephp/plugin-installer    0.0.15             A composer installer fo...
sdustinh@claudia:~/github/app$ php --version
PHP 7.0.8-3+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-3+deb.sury.org~trusty+1, Copyright (c) 1999-2016, by Zend Technologies
sdustinh@claudia:~/github/app$ mysql --version
mysql  Ver 14.14 Distrib 5.6.30, for debian-linux-gnu (x86_64) using  EditLine wrapper
sdustinh@claudia:~/github/app$ lsb_release -d -r
Description:    Ubuntu 14.04.4 LTS
Release:    14.04

What you did

All of the migrations were created with bake. The short of it is i ran something like this:

bin/cake migrations migrate -p Users
bin/cake migrations seed -p Users
bin/cake migrations rollback -p Users

More details below.

Actual Behavior

Basically, it looks like the migrate/seed/rollback commands do as they are supposed to. The problem looks like after the rollback command has finished. I sifted through the source and wasn't able to find anything (with the exception maybe being the event - no idea what is listening to it).

The rollback it completed but the exception is still thrown. Just for kicks I wiped the database and deleted the schema-dump-default.lock file then ran bin/cake migrations rollback -p Users. The rollback completed and the exception was still thrown. I assume what is happening is the dump command is fired off after rollback every time and it tries to load a table that does not exist.

This bug doesn't seem to impede the functionality of the plugin but it does throw an exception every time rollback is run.

Very Detailed Behavior

sdustinh@claudia:~/github/app$ bin/cake migrations migrate -p Users -vvv > logs/migrate_users.log
sdustinh@claudia:~/github/app$ bin/cake migrations seed -p Users -vvv > logs/seed_users.log
sdustinh@claudia:~/github/app$ bin/cake migrations rollback -p Users -vvv > logs/rollback_users.log


  [Cake\Database\Exception]                                               
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app  
  .user_groups' doesn't exist                                             



  [PDOException]                                                          
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app  
  .user_groups' doesn't exist                                             


dump [-p|--plugin PLUGIN] [-c|--connection CONNECTION] [-s|--source SOURCE]

sdustinh@claudia:~/github/app$ 

logs/migrate_users.log

[36mWelcome to CakePHP v3.2.12 Console[0m
---------------------------------------------------------------
App : src
Path: /home/sdustinh/github/app/src/
PHP : 7.0.8-3+deb.sury.org~trusty+1
---------------------------------------------------------------
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds
 -- createTable('users_phinxlog')
    -> 0.2446s
using environment default
using adapter mysql
using database app

 == 20160709163852 Initial: migrating
 -- createTable('users')
    -> 0.4022s
 -- createTable('user_groups')
    -> 0.3013s
 -- createTable('user_group_members')
    -> 0.2762s
 -- createTable('user_profiles')
    -> 0.2776s
 -- createTable('user_roles')
    -> 0.2929s
 -- createTable('user_role_members')
    -> 0.2929s
 -- createTable('user_statuses')
    -> 0.2678s
 -- createTable('user_tokens')
    -> 0.3026s
 == 20160709163852 Initial: migrated 2.4519s

All Done. Took 2.4578s
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds
Writing dump file `/home/sdustinh/github/app/plugins/Users/config/Migrations/schema-dump-default.lock`...
Dump file `/home/sdustinh/github/app/plugins/Users/config/Migrations/schema-dump-default.lock` was successfully written

seed_users.log

[36mWelcome to CakePHP v3.2.12 Console[0m
---------------------------------------------------------------
App : src
Path: /home/sdustinh/github/app/src/
PHP : 7.0.8-3+deb.sury.org~trusty+1
---------------------------------------------------------------
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds
using environment default
using adapter mysql
using database app

 == GroupsSeed: seeding
 == GroupsSeed: seeded 0.0688s

 == RolesSeed: seeding
 == RolesSeed: seeded 0.0888s

 == StatusesSeed: seeding
 == StatusesSeed: seeded 0.0998s

All Done. Took 0.2974s

rollback_users.log

[36mWelcome to CakePHP v3.2.12 Console[0m
---------------------------------------------------------------
App : src
Path: /home/sdustinh/github/app/src/
PHP : 7.0.8-3+deb.sury.org~trusty+1
---------------------------------------------------------------
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds
using environment default
using adapter mysql
using database app

 == 20160709163852 Initial: reverting
 -- dropTable('user_tokens')
    -> 0.1083s
 -- dropTable('user_statuses')
    -> 0.1008s
 -- dropTable('user_role_members')
    -> 0.1008s
 -- dropTable('user_roles')
    -> 0.1173s
 -- dropTable('user_profiles')
    -> 0.1269s
 -- dropTable('user_group_members')
    -> 0.1257s
 -- dropTable('user_groups')
    -> 0.1090s
 -- dropTable('users')
    -> 0.1009s
 == 20160709163852 Initial: reverted 0.9303s

All Done. Took 0.9352s
using migration path /home/sdustinh/github/app/plugins/Users/config/Migrations
using seed path /home/sdustinh/github/app/plugins/Users/config/Seeds

sdustinh avatar Jul 09 '16 18:07 sdustinh

@sdustinh Would it be possible for you to provide us the migrations and seeds file please ?

HavokInspiration avatar Oct 24 '16 20:10 HavokInspiration

Definitely. I'll try to have this for you by the end of the day when I get some free time.

sdustinh avatar Oct 25 '16 17:10 sdustinh

Thanks @sdustinh. Is your current setup (package version number) the same as the one from your original ticket ?

HavokInspiration avatar Oct 26 '16 06:10 HavokInspiration

Hi @sdustinh. Any update on the migrations and seeds files of your setup ?

HavokInspiration avatar Dec 13 '16 21:12 HavokInspiration

Sorry! I forgot about this completely. So the problem tracks down to a combination of the migrations plugin and one of my behaviors when not using the rollback --no-lock flag.

I had a behavior that uses $table->hasField() on the initialize() method. This was triggering the schema collection to describe('table_name') which was causing the Cake\Database\Schema\Collection::_reflect() method to throw an exception.

Everything seems to be working properly, but I don't know if throwing that exception is desired behavior as it doesn't technically do anything wrong. The pain is that the exception will block any other subsequent commands from running that may be contained in a shell script.

sdustinh avatar Oct 09 '17 15:10 sdustinh

I'm having this issue too in version 2.0.0. It seems like it has to happen only when I added a behavior to the table class (it was fixed when I commented the addBehavior out).

Danoctum avatar Dec 17 '19 14:12 Danoctum

Came across this issue today and @Danoctum solution worked

My rollback kept saying couldn't delete the table because it didn't exist

public function up()
    {
        $table = $this->table('processors');
        $table
            ->addColumn('name', 'string', [
                'default' => '',
                'limit' => 191,
                'null' => false,
            ])
            //...
            ->create();
    }

    public function down()
    {
        $this->table('processors')->drop()->save();
    }
bin/cake migrations migrate

Confirm the table does exist

bin/cake migrations rollback

rollback throws the error

Base table or view not found: 1146 Table 'database.processors' doesn't exist

But the table has in fact been dropped

Commented out a plugin on the ProcessorsTable.php, rerun the up and down

$this->addBehavior('Timestamp');
//        $this->addBehavior('Muffin/Slug.Slug');

The expected result is achieved, table is created and dropped without any errors.

It seems like it is trying to drop the table twice because the table truly has gone after you run the rollback, sorry not sure why.

My migration version: "cakephp/migrations": "^2.0.0" (2.4.2)

solocommerce avatar May 10 '20 01:05 solocommerce