Question

From config/main.php :

    'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=testdb',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ),

When I use the gii model generator (http://localhost/yii/testdelete/index.php?r=gii/model) and try to put "post" or "user" in the table name and click "Preview" it says:

Table 'post' does not exist.

I want to be able to create models using those tables.

Exporting from phpMyAdmin:

-- Host: 127.0.0.1
-- Database: `testdb`

CREATE TABLE IF NOT EXISTS post ( id int(10) unsigned NOT NULL AUTO_INCREMENT, created_on int(11) unsigned NOT NULL, title varchar(255) COLLATE utf8_unicode_ci NOT NULL, content text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS user ( id int(10) unsigned NOT NULL AUTO_INCREMENT, username varchar(200) COLLATE utf8_unicode_ci NOT NULL, password char(40) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

Was it helpful?

Solution

If you type "s" into Table Name field auto complete should pop up with both tables.

check that

  1. you have saved the config file (close it and open again to verify its content)
  2. you have one db section in your config file (maybe you have sqlite one overwriting it)
  3. check that you are on same mysql instance. phpMyAdmin host 127.0.0.1 doesnt meant its the same instance, its the instance phpMyAdmin runs on (check the url). Login from command line (or use wonderful desktop client http://www.heidisql.com/) to poke around in localhost database
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top