Cphalcon: Why ORM is requesting a field, that was removed from the table?

Created on 15 Sep 2017  路  6Comments  路  Source: phalcon/cphalcon

Hi everyone,

I have a really weird situation with metadata ORM. I removed one column (_category_old_) from the mySQL table, but it's there in the model. Clean all cache files, restart php5-fpm, and nothing happens.

It just shows this message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Article.category_old' in 'field list

I double checked the code and looked for that field in the model, and it's not there, but if I look in the raw request to database, it's there.
Then I decided to check metadata on APC itself and got two different results.

$Article = new Article();

#Test 1
$metaData = new \Phalcon\Mvc\Model\MetaData\Apc();
$attributes = $metaData->getAttributes( $Article );
print_r($attributes);
/*
Array
(
    [0] => id
    [1] => title
)
*/

#Test 2
$metaData = $Article->getModelsMetaData();
var_dump( get_class( $metaData ) );   //Phalcon\Mvc\Model\MetaData\Apc
$attributes = $metaData->getAttributes( $Article );
print_r($attributes);
/*
Array
(
    [0] => id
    [1] => title
    [2] => category_old
)
*/

I'm not quite sure, if it has something to do with my issue, but I would like to understand why there's a request to the old field, which doesn't exist anymore.

Thank you for your attention.

Any advice would be really appreciated.

  • Phalcon version: 3.0.0
  • PHP Version: PHP 5.5.9-1ubuntu4.21
  • Server: Nginx

Most helpful comment

It's because your models meta data is reading from a cached source. Likely files perhaps. Fix your modelsMetadata initialization.

User error. Close.

All 6 comments

It's because your models meta data is reading from a cached source. Likely files perhaps. Fix your modelsMetadata initialization.

User error. Close.

#Test 2
$metadata = $Article->getModelsMetaData();
var_dump( get_class( $metadata ) );

PhalconMvcModelMetaDataApc

@virgofx , if I were you, I would have replied the same.

The problem is that removing the column works fine on a clone server. Just remove the field from the database, restart php5-fpm, and that's it.

But on the live server it doesn't work, and here's what I've tried to do:

  • I tried to clean the cache using with apc_clear_cache() function.
  • Rebooted the server.

Decided to disable PhalconMvcModelMetadataApc in modelsMetadata and everything started to work. I turn it back on, and everything stops working.

How can I clear APC?
Or see all its variables?

You tried this, right?

apc_clear_cache();
apc_clear_cache('user');
apc_clear_cache('opcode');

@oscarmolinadev, It worked !

I tried only apc_clear_cache();
Sorry for wasting your time, I really appreciate it!
Thank you very very very much for help.

P.s. But I still don't understand why the cache hadn't been cleaned after php5-pfm restart.

Good luck everyone!

@oscarmolinadev,
It works, but not for a long time. After around 5 mins, it requests fields from the cache, which doesn't exsist. Another cache cleaning helps only for a short time.

Also I tried to change the APC prefix and to clean the cache one more time - didn't help, same result.

Do you have any ideas, except to cut APC cache out from the project?

Was this page helpful?
0 / 5 - 0 ratings