Reputation: 2610
I am creating a cakephp 2.x application. Midway through development, I suddenly found myself with a "table not found" error.
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
I checked my database and the associated table was actually there.
Next, I try to debug the Model. The model can access the table. The error about cakephp unable to find the datatable persists.
This is what I get when I debug the model:
\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
)
}
I have also tried the following creating new table instead for the model to use. The model can access the new table, but CakePHP still cannot detect these new tables.
Please advise.
Upvotes: 3
Views: 9822
Reputation: 1
For those that have this similar problem:
I have respected cake's conventions too but it was still unable to find that table. I tried the method with 'debug 2/0' with no success too.
The 'magic' happened when I loaded another model that I created - only that one first, and then both of them. This method worked for me.
Upvotes: 0
Reputation: 10812
I found this question when I was googling.
I had a similar issue.
I kept being prompted that I do not have a particular table when it was obviously there and I was following the conventions in naming the table as plural form.
I even cleared the cake cached files several times to no avail.
Then I changed the debug mode from 0 to 2. Suddenly the error was gone.
Then I changed the debug mode from 2 back to 0. The error was still gone.
This is a weird behavior. And I am not sure exactly how to duplicate it. I am writing this down in case somebody else faced the same issue as me.
UPDATE: I have realized that for one of my apps that frequently has this problem, somehow the jenkins tasks causes some files in tmp/cache/persistent to have files in the wrong user:group.
I have corrected this yesterday. As of now, this problem has yet to appear. If the problem did not occur after another 10 days or so, I will declare that the problem is because the tmp files are not in the right permissions or user:group ownership.
Upvotes: 16