0

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),
         ],
     ]
4
  • 1
    Schema caching does seem the most obvious cause. Just clear the cache? Commented Nov 12, 2024 at 14:52
  • I tried disabling the cache both by changing 'cacheMetadata' to false and by adding versioning to the cake_model prefix I don't know why it didn't work, but I just tried cleaning it manually on the poc cli in the dev environment and it was successful. But the problem now is that every time there's a deletion on the database I have to redeploy but then it takes a few minutes of errors witch is unideal in a prod env. Any ideas on what could be done? Commented Nov 13, 2024 at 17:44
  • 1
    Just add a cache clear to your deploy process. Commented Nov 13, 2024 at 18:58
  • The command is bin/cake cache clear_all etc. This should always be done with any (db) migration. Then there should be no issues if your code doesnt call invalid columns itself. Commented Nov 15, 2024 at 19:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.