2013-03-02 19 views
1

我使用WAMP,MYSQL database.i Yii中工作創建表原樣誼無法查找表

CREATE TABLE IF NOT EXISTS `balaee_dev`.`country` (
    `countryId` INT(11) NOT NULL AUTO_INCREMENT , 
    `country` VARCHAR(45) NULL DEFAULT NULL , 
    PRIMARY KEY (`countryId`) , 
    UNIQUE INDEX `country_UNIQUE` (`country` ASC)) 
ENGINE = InnoDB 
DEFAULT CHARACTER SET = utf8; 

當我測試的項目here - 它給我這個錯誤:

「的在數據庫中找不到活動記錄類「country」的表「country」,儘管該表存在於數據庫中。我收到每個控制器的這個錯誤。下面是我的配置文件:

<?php 

// This is the configuration for yiic console application. 
// Any writable CConsoleApplication properties can be configured here. 
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 
    'name'=>'My Console Application', 
    // application components 
    'components'=>array(
     'db'=>array(
      'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', 
     ), 
     // uncomment the following to use a MySQL database 

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

    ), 
); 

,我有main.php AS-

<?php 

// uncomment the following to define a path alias 
// Yii::setPathOfAlias('local','path/to/local-folder'); 

// This is the main Web application configuration. Any writable 
// CWebApplication properties can be configured here. 
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 
    'name'=>'My Balaee Application', 
    // preloading 'log' component 
    'preload'=>array('log'), 
    // autoloading model and component classes 
    'import'=>array(
     'application.models.*', 
     'application.components.*', 
     'application.modules.KnowledgePortal.*', 
     'application.modules.QuestionBank.*', 
     //'application.modules.UserAuthentication.*', 
     'application.plugins.*', 
      'application.extensions.noaaWeather.*', 

    ), 
    'modules'=>array(
     //Question Bank Module 
     'QuestionBank'=>array(), 
     //Social Networking Module 
     'SocialNetworking'=>array(), 
     //Knowledge Portal Module 
     'KnowledgePortal'=>array(), 
     // uncomment the following to enable the Gii tool 
     'gii'=>array(
      'class'=>'system.gii.GiiModule', 
      'password'=>'root', 
      // If removed, Gii defaults to localhost only. Edit carefully to taste. 
      'ipFilters'=>array('127.0.0.1','::1'), 
      //'ipFilters'=>array('204.93.172.30'), 
     ), 
    ), 
    // application components 
    'components'=>array(
     'user'=>array(
      // enable cookie-based authentication 
      'allowAutoLogin'=>true, 
     ), 

     'mailer' => array(
       'class' => 'application.extensions.mailer.EMailer', 
       'pathViews' => 'application.views.email', 
       'pathLayouts' => 'application.views.email.layouts' 
     ), 
     'curl'=>array(
     'class' => 'application.extensions.curl.Curl', 
     ), 
     'params'=>array(
     'noaaWeather.cachePath' => 'protected/extensions/noaaWeather/cache' 
     ), 

     // uncomment the following to enable URLs in path-format 
     'urlManager'=>array(
      'urlFormat'=>'path', 
      'rules'=>array(
       '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
       '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
       '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
      ), 
     ), 
/* 
     'db'=>array(
      'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', 
     ), 
*/ 

    'db'=>array(
      //'connectionString' => 'mysql:host=localhost;dbname=balaee_dev', 
      'connectionString' => 'mysql:host=204.93.172.30;dbname:shailani_balaee_dev', 
      //'emulatePrepare' => true, 
      'username' => 'shailani_bdev', 
      'password' => 'nTRXpfuH8wmjx5hV', 
      'charset' => 'utf8', 
     ),  
     // uncomment the following to use a MySQL database 

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

     'errorHandler'=>array(
      // use 'site/error' action to display errors 
      'errorAction'=>'site/error', 
     ), 
     'log'=>array(
      'class'=>'CLogRouter', 
      'routes'=>array(
       array(
        'class'=>'CFileLogRoute', 
        'levels'=>'error, warning', 
       ), 
       // uncomment the following to show log messages on web pages 
       /* 
       array(
        'class'=>'CWebLogRoute', 
       ), 
       */ 
      ), 
     ), 
    ), 

    // application-level parameters that can be accessed 
    // using Yii::app()->params['paramName'] 
    'params'=>array(
     // this is used in contact page 
     'adminEmail'=>'[email protected]', 
    ), 
); 

所以請能有人指導我什麼樣的變化,我需要做什麼呢?

+0

您發佈了控制檯應用程序('console.php')的配置。發佈'main.php'的內容 – dInGd0nG 2013-03-02 07:05:09

+0

評論或刪除此行:'db'=> array( 'connectionString'=>'sqlite:'。dirname(__ FILE __)。'/ ../data/testdrive.db' , ), – 2013-03-02 07:51:50

+0

謝謝主席的回覆..我編輯了包含main.php文件的代碼... – user1947777 2013-03-02 10:11:06

回答

1

你說你在使用MySQL。所以你的配置中的sqlite行不會出現。 提供的表格已經在你的MySQL數據庫中實際創建(我想你可以看到他們在MySQL工作臺或在phpMyAdmin):

  • 刪除此行
  • 重新運行模型/ CRUD /不管一代。

如果你的連接字符串和參數是可以的,它應該工作。

如果沒有,請隨意在這裏複製相關的錯誤日誌:Yii,MySql和Apache的日誌可以包含有用的信息。