Yii 框架:在数据库中找不到活动记录类的表 [英] Yii Framework: The table for active record class cannot be found in the database

查看:23
本文介绍了Yii 框架:在数据库中找不到活动记录类的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 hivemind 有更多关于处理 Yii 框架中的错误的建议.特定于我们的设置的确切错误是:

I'm hoping the hivemind has some more suggestions on dealing with this error from Yii Framework. The exact error, specific to our setup is:

CDbException 活动记录类用户"的用户"表在数据库中找不到.

CDbException The table "users" for active record class "Users" cannot be found in the database.

我使用的是来自 SVN 的 Yii Framework 1.1.11-dev,尽管这只是为了解决问题.我们运行的是最新的稳定版本 1.1.10.

I'm using Yii Framework 1.1.11-dev from SVN, though this was just an attempt to fix the problem. We were running the latest stable version 1.1.10.

我们正在尝试使用在我的开发环境中工作的代码部署到我们的实时服务器.我觉得问题几乎可以肯定是数据库配置差异,但我不确定在哪里可以找到它.

We are trying to deploy to our live server with code that is working in my dev env. I feel like the problem is almost certainly a database configuration difference, but I'm not sure where to find it.

我已经在这里搜索并搜索了 Yii 论坛,在那里我发现这个问题列出了几次.我们已经尝试过的建议修复包括

I have already searched here and searched the Yii forums where I found this problem listed a couple of times. Suggested fixes we've already tried include

  • 从 dsn 中删除主机和端口
  • 有和没有表名模式(即users"和public.users")
  • 将所有数据库 [dbname] 授予 postgres
  • 使用找到的代码授予数据库中每个表的所有权限 这里

环境如下:

  • 开发 - OSX 10.7、PHP 5.3.10、PostgreSQL 9.0.3
  • PROD - FC15、PHP 5.3.10、PostgreSQL 9.0.7

错误表明表users"不存在,尽管它很明显存在.

The error indicates the table "users" does not exist, though it quite clearly does.

~$ psql -U postgres
psql (9.0.7)
Type "help" for help.

postgres=# dt
                    List of relations
 Schema |             Name             | Type  |  Owner   
--------+------------------------------+-------+----------
  { ... removed for brevity ... }
 public | users                        | table | postgres

我们在protected/config/main.php中的配置

Our configuration in protected/config/main.php

'db'=>array(
    'connectionString' => 'pgsql:dbname=lppsync',
    'emulatePrepare' => true,
    'username' => 'postgres',
    'password' => '',
),

用户模型的相关部分是

class Users extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Users the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'users';
    }

推荐答案

原来数据没有导入到指定的数据库中.相反,它被导入到用户的数据库中.在这种情况下,'postgres'.这种情况下的解决方法是将数据重新导入到正确的位置,或者更改 Yii 配置(我们的决定).新的连接设置:

It turns out the data was not imported to the named database. Instead it was imported to the user's database. In this case 'postgres'. The fix in this case is to re-import the data to the correct location, or change the Yii config (our decision). New connection settings:

'db'=>array('connectionString' => 'pgsql:dbname=postgres', 'emulatePrepare' => true, 'username' => 'postgres','password' => '',)

这篇关于Yii 框架:在数据库中找不到活动记录类的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆