Trying to run migration results in SQLSTATE[42S02]


#1

Hii there,

I had to reinstall my laptop so now I have to re-run my migrations.
These migrations did work before just fine (so we can pretty much rule out the migrations themselves being the issue) but all of the sudden, it just decided to give up and throw errors and I have no clue what causes them or when they started to happen (I only noticed this afternoon because I had to re-run them).

The command I use is bin/cake migrations migrate -p Kikioboeru/Kikioboeru.
Running simply bin/cake produces the same issue.

This is the stacktrace it produces:

2019-01-07 18:07:46 Error: [Cake\Database\Exception] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'kikioboeru.options' doesn't exist in /var/www/vendor/cakephp/cakephp/src/Database/Schema/Collection.php on line 131
Stack Trace:
#0 /var/www/vendor/cakephp/cakephp/src/Database/Schema/Collection.php(97): Cake\Database\Schema\Collection->_reflect('Column', 'options', Array, Object(Cake\Database\Schema\TableSchema))
#1 /var/www/vendor/cakephp/cakephp/src/Database/Schema/CachedCollection.php(63): Cake\Database\Schema\Collection->describe('options', Array)
#2 /var/www/vendor/cakephp/cakephp/src/ORM/Table.php(548): Cake\Database\Schema\CachedCollection->describe('options')
#3 /var/www/vendor/cakephp/cakephp/src/ORM/Query.php(271): Cake\ORM\Table->getSchema()
#4 /var/www/vendor/cakephp/cakephp/src/ORM/Query.php(169): Cake\ORM\Query->addDefaultTypes(Object(Kikioboeru\Kikioboeru\Model\Table\OptionsTable))
#5 /var/www/vendor/cakephp/cakephp/src/ORM/Table.php(1758): Cake\ORM\Query->__construct(Object(Cake\Database\Connection), Object(Kikioboeru\Kikioboeru\Model\Table\OptionsTable))
#6 /var/www/vendor/cakephp/cakephp/src/ORM/Table.php(1350): Cake\ORM\Table->query()
#7 /var/www/vendor/cakephp/cakephp/src/ORM/Table.php(2478): Cake\ORM\Table->find('all', Array)
#8 /var/www/vendor/cakephp/cakephp/src/ORM/Table.php(2499): Cake\ORM\Table->_dynamicFinder('find_by_name', Array)
#9 /var/www/plugins/Kikioboeru/Kikioboeru/src/Controller/Component/SettingsComponent.php(70): Cake\ORM\Table->__call('findByName', Array)
#10 /var/www/plugins/Kikioboeru/Kikioboeru/config/bootstrap.php(22): Kikioboeru\Kikioboeru\Controller\Component\SettingsComponent->getOptionValue('site_title')
#11 /var/www/vendor/cakephp/cakephp/src/Core/BasePlugin.php(239): require('/var/www/plugin...')
#12 /var/www/plugins/Kikioboeru/Kikioboeru/src/Plugin.php(21): Cake\Core\BasePlugin->bootstrap(Object(App\Application))
#13 /var/www/vendor/cakephp/cakephp/src/Http/BaseApplication.php(161): Kikioboeru\Kikioboeru\Plugin->bootstrap(Object(App\Application))
#14 /var/www/vendor/cakephp/cakephp/src/Console/CommandRunner.php(193): Cake\Http\BaseApplication->pluginBootstrap()
#15 /var/www/vendor/cakephp/cakephp/src/Console/CommandRunner.php(136): Cake\Console\CommandRunner->bootstrap()
#16 /var/www/bin/cake.php(12): Cake\Console\CommandRunner->run(Array)
#17 {main}

The table options should be created by a migration in the Kikioboeru/Kikioboeru plugin, which is why it’s so odd that I get this, since it’s looking for a table that should be created by running the command.
I am using Cakephp 3.6.14

UPDATE 1: For testing purposes, I have added the table to the database manually, oddly enough resulting in the same exact error.

UPDATE 2: Issue persists with CakePHP 3.6.10 and 3.7.2


#2

I have found the source of the issue.
In the bootstrap.php of the Kikioboeru/Kikioboeru it is trying to load some stuff from the options table.
However, I cannot find a better place to put this in since this code has to run when the plugin gets loaded.
See this topic for why I placed it here.

After some looking around, I figured I should place this in the AppController:initialize instead, which resolved the issue for me.
One slight issue though, is that moving this to the AppController:initialize for said plugin, only runs this code when that plugin is actually used, instead of when it’s loaded.
Any workaround for this?