问题描述
我尝试Google搜索并在此搜索答案,
i tried googling and searched for an answer here too,
问题
即使CakePHP存在,CakePHP也找不到该表。
CakePHP can't find a table even when it exist.
我尝试的:
- 清除缓存文件夹
- 验证表格名称连接字符串。
- 添加useTable =urls
/ strong>
The code
class Url extends AppModel {
public function add_url($the_url,$the_content,$title) {
$this->create();
$this->set('url', $the_url );
$this->set('content', $the_content );
$this->set('title', $title );
$this->save();
}
}
错误: / p>
The error:
错误:未找到模型Url的表网址数据源默认。
Error: Table urls for model Url was not found in datasource default.
也许有人知道这个答案?
Perhaps someone knows the answer to this?
推荐答案
检查缓存问题
消除)缓存相关的问题是简单地:
/**
* Turn off all caching application-wide.
*
*/
Configure::write('Cache.disable', true);
如果这解决了问题,有必要进一步看看为什么以前的努力清除缓存显然失败了。如果使用基于文件的缓存,确保删除 tmp
下的所有文件,如果使用不同的缓存存储,确保实际被清除。
If this solves the problem, it's necessary to take a closer look at why previous efforts to clear the cache apparently failed. If file-based caching is used ensure all files under tmp
are deleted, if a different cache store is being used ensure it's actually being cleared.
另一个相对常见的原因是数据库用户不能有权限列出给定数据库中的表,这可以用相同的方式检查:
Another relatively common cause for what is described is for the database user to not have permission to list the tables in the given database, this can be checked for in the same way a model does it:
$db = ConnectionManager::getDataSource('default');
debug($db->listSources());
die;
如果没有列出任何表 - 检查连接凭据,并确保是没有权限相关的问题。执行通过cli并确保结果符合预期:
If there are no tables listed at all - check the connection credentials and ensure that, for example, there are no permission related problems. Execute the same sql that CakePHP is executing via the cli and ensure that the result is as expected:
$ mysql -uuser -ppassword databasename
mysql> show tables from foo;
+-----------------+
| Tables_in_foo |
+-----------------+
| posts |
| urls |
+-----------------+
2 rows in set (0.00 sec)
如果是列表,则双击,三重和四重检查连接凭据,因为相关代码正常工作,缺少实际上不存在于应用程序正在连接的数据库中。
If there are tables listed - then double, triple and quadruple check the connection credentials as the relevant code is working as expected and the table that is missing does not in fact exist in the database the application is connecting to.
这篇关于CakePHP表即使存在也缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!