Webgrity
Webgrity

Reputation: 99

Missing Database Table cakephp even table is there

I have a database where all tables are prefixed by "bs" . I baked a model from bs_states table and it's generate the following code.

<?php
App::uses('AppModel', 'Model');
/**
 * State Model
 *
 * @property country $Country
 * @property Seller $Seller
 */
class State extends AppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
    public $useTable = '_states';

/**
 * Primary key field
 *
 * @var string
 */
    public $primaryKey = 'state_id';

/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'state_iso';


    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'Country' => array(
            'className' => 'country',
            'foreignKey' => 'country_iso',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

/**
 * hasMany associations
 *
 * @var array
 */
    public $hasMany = array(
        'Seller' => array(
            'className' => 'Seller',
            'foreignKey' => 'state_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );

}

This code is working fine in local system but when I upload it to the prodution server it showing following message.

Missing Database Table Error: Table bsstates for model State was not found in datasource default.

Initially I thought it's a cache issue so I've done the following:

But no luck. I am still facing the same problem. My database connection on production server is good because other model are working fine.

Upvotes: 1

Views: 3737

Answers (3)

Bharat Jain
Bharat Jain

Reputation: 510

instead of writing public $useTable = '_states'; you can write and public $useTable = 'states'; add that underscore() prefix in database configuration in database.php as 'bs_'.

or add public $tablePrefix = 'bs_'; in this file.

Upvotes: 0

Tim Sanders
Tim Sanders

Reputation: 851

First place to look when you're in a production environment is the logs. They also give more information than the debug print out. Navigate to here:

\app\tmp\logs

This error is usually accompanied with insufficient privileges on the table. Make sure the db role for Cake has privileges on that table.

Since you say it works fine locally it makes me think it's a DB privilege issue, but also the CakePHP convention seems to be off.

The Model class name should be:

BsStates

and the class variable $useTable should be:

public $useTable = 'bs_states';

Upvotes: 0

Guillermo Mansilla
Guillermo Mansilla

Reputation: 3889

Remove the $useTable property and use

public $tablePrefix = 'bs_';

Upvotes: 0

Related Questions