I am currently working on removing deprecated columns from my database. After dropping a specific column, I encountered the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'table.my_column' in 'field list'' in /var/www/wap/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php:37
The error is triggered at this line of code:
$info = $this->Infos->find("InfoContact",["gid" => $info_id])->first();
It is using Cake\ORM\Query and the InfoContact entity does not contain any reference to the removed column.
I tried searching the entire code (using Ctrl+Shift+F) for the removed column name but found no explicit references to it. Given this, I think the issue might be related to schema caching in CakePHP. However, I am not entirely certain if caching is indeed the root cause—this is merely a hypothesis at this point.
There is schema caching configured to this project, but I have tried changing 'cacheMetadata' to false and adding versioning to the cake_model prefix but the error persists. Also I have the cakephp/migrations in composer.json but it has no files that extends AbstractMigration
This is how caching is configured in the app.php file:
'Cache' => [
'default' => [
'className' => FileEngine::class,
'path' => CACHE,
'url' => env('CACHE_DEFAULT_URL', null),
],
/**
* Configure the cache used for general framework caching.
* Translation cache files are stored with this configuration.
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true
* If you set 'className' => 'Null' core cache will be disabled.
*/
'_cake_core_' => [
'className' => FileEngine::class,
'prefix' => 'myapp_cake_core_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+1 years',
'url' => env('CACHE_CAKECORE_URL', null),
],
/**
* Configure the cache for model and datasource caches. This cache
* configuration is used to store schema descriptions, and table listings
* in connections.
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true
*/
'_cake_model_' => [
'className' => FileEngine::class,
'prefix' => 'myapp_cake_model_',
'path' => CACHE . 'models/',
'serialize' => true,
'duration' => '+1 years',
'url' => env('CACHE_CAKEMODEL_URL', null),
],
/**
* Configure the cache for routes. The cached routes collection is built the
* first time the routes are processed through config/routes.php.
* Duration will be set to '+2 seconds' in bootstrap.php when debug = true
*/
'_cake_routes_' => [
'className' => FileEngine::class,
'prefix' => 'myapp_cake_routes_',
'path' => CACHE,
'serialize' => true,
'duration' => '+1 years',
'url' => env('CACHE_CAKEROUTES_URL', null),
],
'shortterm' => [
'className' => FileEngine::class,
'prefix' => 'myapp_short_',
'path' => CACHE . 'views' . DS,
'serialize' => true,
'duration' => '+5 minutes'
]
'Datasources' => [
'default' => [
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'timezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => true,
'url' => env('DATABASE_URL', null),
],
]
bin/cake cache clear_alletc. This should always be done with any (db) migration. Then there should be no issues if your code doesnt call invalid columns itself.