CakePHP 数据库表,缺少数据源默认 [英] CakePHP database table, missing datasource default

查看:30
本文介绍了CakePHP 数据库表,缺少数据源默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个类似的问题但我的问题是不同的.

I found this similar question but my problem is different.

我将我的 CakePHP 2.2 应用程序移至另一台服务器.迁移前没有问题.大多数事情在迁移后都能正常工作.我可以访问我的大多数数据库表等.但是当我尝试访问我的一个表时,我收到此错误:

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."

为了解决这个问题,我检查了这个文件夹:/app/tmp/cache/models"

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等等.

但是没有用于统计表的文件.这可能是问题吗?或者我该如何解决这个问题?

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

(/app/tmp/cache/models"文件夹的权限为 755)

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

Database.php中我有这个:

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


正如我在 thaJeztah 的回答评论中指出的那样,在删除 app/tmp/cache/persistent 中的所有文件后,问题解决了.CakePHP 创建了新的模型缓存文件并且它起作用了.一年后,我发现了真正的问题.问题是设置蛋糕模型文件的清晰持续时间.我将清除缓存设置为 +999 天,因此不会重新生成模型文件.在进行模型更改时,您可以为模型缓存清除设置较低的值:


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"
));

推荐答案

您是否检查过您的数据库,例如在 phpMyAdmin 或 MySql 工作台中?数据库中是否存在该表?

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.

[更新]这个建议解决了问题;

app/tmp/cache/persistent/app/tmp/cache/models 中删除所有文件,然后启用调试.您的 SQL 日志/调试应该显示 CakePhp 用于检测数据库中是否存在表的查询.您还可以检查 Cake 是否可以毫无问题地写入 tmp 文件

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

这篇关于CakePHP 数据库表,缺少数据源默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆