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 The table "users" for active record class "Users" cannot be found in the database.
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.
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
- removing the host and port from the dsn
- with and without schema for the tablename (ie "users" and "public.users")
- GRANT ALL ON DATABASE [dbname] TO postgres
- Grant all on each table in the db using code found here
The environments are as follows:
- DEV - OSX 10.7, PHP 5.3.10, PostgreSQL 9.0.3
- PROD - FC15, PHP 5.3.10, PostgreSQL 9.0.7
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
Our configuration in protected/config/main.php
'db'=>array(
'connectionString' => 'pgsql:dbname=lppsync',
'emulatePrepare' => true,
'username' => 'postgres',
'password' => '',
),
And the relevant part of the Users model is
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';
}
I was facing similar error with MySQL. In my case the problem was that I had made a mistake in granting the rights for the user. Running MySQL client I got a proper "command denied message", but from Yii perspective it looked like the tables did not exist at all.
The solution was to grant the rights properly:
grant all on yiiapp.* to 'yii'@'localhost' identified by '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:
Yii caches db metadata, probably that is the issue? Try to clear your metadata cache or disable cache at all.
The /
wwwroot/assets
folder usually contains those cache files.Check also that you haven't run out of space on your device (disk).
Source: Quoting one of the comments to this Question - Yii Framework: The table for active record class cannot be found in the database