CakePHP database table, missing datasource default
Asked Answered
R

2

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"
));
Recede answered 5/2, 2013 at 20:7 Comment(5)
Post your datasource configuration (password can be anonymized) and an output of DESCRIBE stats query.Rebak
@Recede The fact that there is no cache file for it makes me think you may have forgotten to migrate the table.Fini
@Fini I verified that stats table exists in new server.Recede
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.Leela
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 serverLeela
L
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

Leela answered 5/2, 2013 at 21:0 Comment(7)
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.Recede
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.Recede
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.Recede
Glad I could help. Good luck with your project!Leela
Remove all files from app/tmp/cache/persistent and /app/tmp/cache/models, thanks. Remove cached solved my problemMidrash
Thank you..removing files from /app/tmp/cache/models worked for me.Anu
I am facing the similar issue, I have checked database and model is there with the correct name, I have cleared the cache/model and cache/persistent folders, tried replacing localhost with 127.0.0.1 but nothing really worked. Can someone help me out here, Is that can be database permission issue?Sniperscope
K
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.

Kilkenny answered 7/12, 2020 at 15:27 Comment(1)
for me it work.Rossanarosse

© 2022 - 2024 — McMap. All rights reserved.