【发布时间】:2014-07-21 13:51:04
【问题描述】:
我有一个数据库,其中所有表都以 "bs" 为前缀。我从 bs_states 表中烘焙了一个模型,它生成了以下代码。
<?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' => ''
)
);
}
此代码在本地系统中运行良好,但是当我将其上传到生产服务器时,它显示以下消息。
缺少数据库表 错误:在数据源默认值中找不到模型状态的表 bsstates。
最初我认为这是一个缓存问题,所以我做了以下操作:
- 我已经清除了 tmp/cache 目录
- 我将调试模式
Configure::write('debug', 0);改为Configure::write('debug', 2);
但没有运气。我仍然面临同样的问题。我在生产服务器上的数据库连接很好,因为其他模型工作正常。
【问题讨论】:
-
你确定吗?您的代码说它应该在
bs和states之间有一个下划线:public $useTable = '_states'; -
也粘贴你的数据库文件(显然不包括用户名/密码)
-
数据库中的表名是什么?
-
@Andy 是的,它在我的本地系统中运行良好。
-
而不是 public $useTable = 'states';你可以写 public $useTable = 'states';并在 database.php 中的数据库配置的前缀中添加下划线()作为“bs_”。
标签: php cakephp cakephp-2.0 cakephp-2.3 cakephp-model