我正在创建一个cakephp 2。x应用程序。在开发过程中,我突然发现自己出现了"table not found"错误。
Missing Database Table
Error: Table blocked for model Parental was not found in datasource default.
Notice: If you want to customize this error message, create project'View'Errors'missing_table
我检查了我的数据库,相关的表实际上在那里。
接下来,我尝试调试模型。模型可以访问表。关于cakephp无法找到数据表的错误仍然存在。
这是我调试模型时得到的结果:
'project'Controller'ParentalsController.php (line 5)
object(Parental) {
useTable => 'blocked'
useDbConfig => 'default'
id => null
data => array()
schemaName => null
table => 'blocked'
primaryKey => 'id'
validate => array()
validationErrors => array()
validationDomain => null
name => 'Parental'
alias => 'Parental'
tableToModel => array(
'blocked' => 'Parental'
)
cacheQueries => false
belongsTo => array()
hasOne => array()
hasMany => array()
hasAndBelongsToMany => array()
actsAs => null
Behaviors => object(BehaviorCollection) {
modelName => 'Parental'
defaultPriority => (int) 10
}
whitelist => array()
cacheSources => true
findQueryType => null
recursive => (int) 1
order => null
virtualFields => array()
__backAssociation => array()
__backInnerAssociation => array()
__backOriginalAssociation => array()
__backContainableAssociation => array()
findMethods => array(
'all' => true,
'first' => true,
'count' => true,
'neighbors' => true,
'list' => true,
'threaded' => true
)
}
我还尝试了以下创建新表,而不是模型使用。模型可以访问新表,但是CakePHP仍然不能检测到这些新表。
请建议。
我是在谷歌上找到这个问题的
我也遇到过类似的问题。
我一直被提示我没有一个特定的表,当它明显存在时,我遵循惯例将表命名为复数形式。
我甚至清理了几次蛋糕缓存文件,但都无济于事。
然后我将调试模式从0改为2。突然,错误消失了。
然后我把调试模式从2改回0。错误仍然存在。
这是一个奇怪的行为。我也不知道怎么复制它。我把这些写下来,以防别人遇到和我一样的问题。
更新:我已经意识到,对于我的一个经常有这个问题的应用程序,不知何故,jenkins任务导致tmp/cache/persistent中的一些文件在错误的user:group中有文件。
我昨天已经改正了。到目前为止,这个问题还没有出现。如果再过10天左右问题还没有出现,我就声明问题是由于tmp文件没有正确的权限或user:group所有权。
对于有类似问题的人:
我也尊重蛋糕的惯例,但它仍然找不到那张桌子。我用'debug 2/0'尝试了这个方法,也没有成功。
当我加载我创建的另一个模型时,"神奇"发生了——首先只有一个模型,然后是两个模型。这个方法对我很有效。