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

查看:304
本文介绍了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."

模型

在该文件夹中,每个表都有一个文件

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

但没有stats表的文件。可以是问题吗?

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)

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

[update] 此建议可能会导致数据库转储被部分导入。解决问题;

[update] this suggestion solved the problem;

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天全站免登陆