6

I found this similar question but my problem is different.

I moved my CakePHP 2.2 application to another server. There exists no problem before migration. Most of the things works fine after migration. I can reach most of my database tables etc. But when I try to reach one of my table I get this error:

"Error 500: Table stats for model Stat was not found in datasource default."

To solve this, I checked this folder: "/app/tmp/cache/models"

In that folder there is a file for each of my tables

  • myapp_cake_model_default_mydatabase_table1
  • myapp_cake_model_default_mydatabase_table2
  • myapp_cake_model_default_mydatabase_table3 etc..

But there is no file for stats table. Can it be the problem? Or how can I solve this?

(Permission for "/app/tmp/cache/models" folder is 755)

In Database.php I have this:

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'myuser',
    'password' => 'mypass',
    'database' => 'mydatabase',
    'prefix' => '',
    'encoding' => 'utf8',
);

Edit:
As I noted in thaJeztah's answer's comments, after removing all files inside app/tmp/cache/persistent problem solved. CakePHP created new model cache files and it worked. After one year I found out the real problem. The problem was setting cake model files' clear duration. I set clearing cache to +999 days, so model files aren't regenerated. While making model changes you can set lower values for model cache clear:

Cache::config('_cake_model_', array(
    'engine' => "File",
    'prefix' => "myapp_". 'cake_model_',
    'path' => CACHE . 'models' . DS,
    'serialize' => ($engine === 'File'),
    'duration' => "+999 days"
));
5
  • Post your datasource configuration (password can be anonymized) and an output of DESCRIBE stats query. Commented Feb 5, 2013 at 20:45
  • @trante The fact that there is no cache file for it makes me think you may have forgotten to migrate the table. Commented Feb 5, 2013 at 20:49
  • @luchomolina I verified that stats table exists in new server. Commented Feb 5, 2013 at 21:08
  • 1
    Remove all files from app/tmp/cache/persistent and /app/tmp/cache/models then enable debugging. Your SQL log/debug should show the queries that CakePhp is using to detect if the tables exist in the database. Also you'll be able to check if Cake writes to the tmp files without problems. Commented Feb 5, 2013 at 21:16
  • 1
    Another idea: might it be possible that APC is installed on the new server? CakePHP defaults to using APC in stead of File caching if APC is installed. In that case, be sure you have a unique cache prefix set, otherwise it may be using caches from another CakePHP website on the same server Commented Feb 5, 2013 at 21:19

2 Answers 2

27

Have you checked your database, e.g. in phpMyAdmin or MySql workbench? Does the table exist in the database?

The error message indicates that the table could not be accessed using the default connection. It's possible that the table is really missing, or that the user you're using to connect to the database does not have the right permissions for that table.

If you migrated the database from another server, did you get error messages while importing? If you did not create a dump enclosed in a transaction, it's possible that the database dump was only partially imported.

[update] this suggestion solved the problem;

Remove all files from app/tmp/cache/persistent and /app/tmp/cache/models then enable debugging. Your SQL log/debug should show the queries that CakePhp is using to detect if the tables exist in the database. Also you'll be able to check if Cake writes to the tmp files without problems

Sign up to request clarification or add additional context in comments.

7 Comments

I'm sure that table exists in new server. I didn't make anything for table permissions. I wouldn't reach other tables if I don't have permission.
I didn't get any error. I dropped stats table from new server. Dumped id from old server and imported to new server again. Problem still exists.
After trying your idea in question comments (removing "app/tmp/cache/persistent" files), Cake created right model files in persistent directory and everything works fine. Thank you.
Glad I could help. Good luck with your project!
Remove all files from app/tmp/cache/persistent and /app/tmp/cache/models, thanks. Remove cached solved my problem
|
1

If this is helpfull for anyone in 2020. I had this problem even with full permissions to the model. I tried doing like @theJeztah suggested which was clearing cache/persistent but the problem persisted. What ended up working was switching Configure::write('debug', 0) to Configure::write('debug', 2) in the app/core file. Presumably on debug it clears the cache better.

1 Comment

for me it work.

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.