Error: SQLSTATE[42S02]: Base table or view not found

user860511 picture user860511 · Oct 16, 2012 · Viewed 10.2k times · Source

I am using CakePHP Version 2.2.3. Having imported my database into PHPMyAdmin, I went on to create my MVC sing CakePHP's bake console. This all went well, I declared my relationships etc...

The problem occurs on creating the last 'view' (All the models/controllers were created without error).

The full error is: Error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'website.connections' doesn't exist

Where as I can confirm it does exist, both table,controller,model and view!

I'm exceptionally confused, any help would be greatly appreciated.

Many thanks in advance.

Update

On the 'Members' model, on commenting out the 'Has Many' code relating to Connections, the error then appears for the next relationship below it. The relationship code is:

public $hasMany = array(
    'Connections' => array(
        'className' => 'Connections',
        'foreignKey' => 'Member_ID',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    ),
    'Recommendations' => array(
        'className' => 'Recommendations',
        'foreignKey' => 'Member_Being_Recommended_ID',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    ),
    'Groups' => array(
        'className' => 'Groups',
        'foreignKey' => 'Member_ID',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    )
);

So once the 'connections' relationship is commented out, the error then moves onto Recommendations, the one below it.

Answer

ADmad picture ADmad · Oct 19, 2012

As per CakePHP's conventions all model names should be singular not plural, so that's the first thing you should fix.