migrations icon indicating copy to clipboard operation
migrations copied to clipboard

[2.0.0-2.0.4] Bake migration_snapshot throws exception when trying to mark migrated

Open challgren opened this issue 5 years ago • 6 comments

So I created a new app following the instructions on cakephp/app and when baking my first migration using the bin/cake bake migration_snapshot Initial the following exception is generated. However the migration file is generated but the phinx tables are not generated and the migration is not marked as applied. I'm not sure if this should be reported in cakephp/cakephp or cakephp/migrations or here. However if I do bin/cake migrations mark_migrated the phinx table is generated and the migration is mark as migrated. I know @wrdx on Slack was also experiencing this issue.

When I first created my original 4.x app I was able to successfully bake a migration and it be run. That migration is dated 20191222 so I'm not sure if something changed in the past month that would be causing this new error.

Mac-mini:bequest challgren$ bin/cake bake migration_snapshot Initial

Creating file /Users/challgren/Projects/bequest/config/Migrations/20200126121547_Initial.php
Wrote `/Users/challgren/Projects/bequest/config/Migrations/20200126121547_Initial.php`
Marking the migration 20200126121547_Initial as migrated...
Exception: Shell class for "Migrations" could not be found. If you are trying to use a plugin shell, that was loaded via $this->addPlugin(), you may need to update bin/cake.php to match https://github.com/cakephp/app/tree/master/bin/cake.php
In [/Users/challgren/Projects/bequest/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php, line 332]

challgren avatar Jan 26 '20 12:01 challgren

I was the one asking about the issue on Slack @challgren, you might want to edit your answer so the Wouter you tagged won't get bothered with updates ;)

Is there a way to work around this until it's fixed?

WrDX avatar Jan 28 '20 10:01 WrDX

Run bin/cake migrations mark_migrated after you bake your migration_snapshot/diff

challgren avatar Jan 28 '20 10:01 challgren

I transferred the issue to correct place

and I wanna convert this shell/task (mark_migrated) to command soon

saeideng avatar Jan 28 '20 11:01 saeideng

Also the schema lock is not being updated which causes problems for further migration_diff generation.

Ali1 avatar Feb 29 '20 16:02 Ali1

As a workaround modify SnapshotTrait.php and replace 2 lines around line 66 with

        $this->_io->out('Marking the migration ' . $fileName . ' as migrated...');
        debug($dispatchCommand);
        //$this->dispatchShell($dispatchCommand);

And around line 87 with:


        $this->_io->out('Creating a dump of the new database state...');
        debug($dispatchCommand);
        //$this->dispatchShell($dispatchCommand);

This will output two commands that you can use and run manually (bin/cake .....) to achieve normal behavior

Ali1 avatar Feb 29 '20 17:02 Ali1

PR welcome if this is still an issue.

dereuromark avatar Apr 11 '20 13:04 dereuromark

This is fixed in Cake5 right?

dereuromark avatar Feb 21 '24 03:02 dereuromark

This is fixed in Cake5 right?

I think it's fixed in all recent versions

challgren avatar Feb 21 '24 03:02 challgren