gpt4 book ai didi

php - CakePHP 表即使存在也丢失

转载 作者:可可西里 更新时间:2023-11-01 14:03:08 24 4
gpt4 key购买 nike

我也尝试使用谷歌搜索并在这里寻找答案,

问题

CakePHP 找不到表,即使它存在。

我尝试了什么:

  1. 清除缓存文件夹
  2. 验证表名和连接字符串。
  3. 添加 useTable = "urls"

代码

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();
}
}

错误:

Missing Database Table

Error: Table urls for model Url was not found in datasource default.

也许有人知道这个问题的答案?

最佳答案

检查缓存问题

识别(或消除)缓存相关问题的一种方法是简单地disable the cache :

/**
* Turn off all caching application-wide.
*
*/
Configure::write('Cache.disable', true);

如果这解决了问题,则有必要仔细研究为什么之前清除缓存的努力显然失败了。如果使用基于文件的缓存,请确保删除 tmp 下的所有文件,如果使用不同的缓存存储,请确保它实际上已被清除。

是否缺少一张表,或者根本没有报告表?

所描述内容的另一个相对常见的原因是数据库用户无权列出给定数据库中的表,这可以用相同的方式检查 a model does it :

$db = ConnectionManager::getDataSource('default');
debug($db->listSources());
die;

如果根本没有列出任何表 - 检查连接凭据并确保没有权限相关的问题。执行 the same sql that CakePHP is executing通过 cli 并确保结果符合预期:

$ mysql -uuser -ppassword databasename
mysql> show tables from foo;
+-----------------+
| Tables_in_foo |
+-----------------+
| posts |
| urls |
+-----------------+
2 rows in set (0.00 sec)

如果列出了 表 - 然后双重、三次和四次检查连接凭据,因为相关代码按预期工作并且缺少的表实际上不存在于应用程序的数据库中正在连接到。

关于php - CakePHP 表即使存在也丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19249650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com