Yii不知道我的数据库的变化

时间:2014-10-13 10:22:38

标签: php database yii oracle10g

我对Yii很陌生,我已经用 Yii 工作了3个星期, Yii 对我帮助很大。我的应用程序工作正常,直到我的同事需要在数据库中进行一些更改。他们删除了一个名为STORE_PROCESSOR的表,并创建了两个名为BIG_STORE_PROCESSORSMALL_STORE_PROCESSOR的新表。他们还在表格中添加了一个新列。

问题是当我尝试使用Gii为这些新表创建模型时,Gii告诉这些表不存在于数据库中。 Gii知道的是STORE_PROCESSOR表仍然存在于数据库中。 CActiveRecord也不知道已添加到表格中的新列。

  • 有没有办法让Yii了解我数据库的变化?

我们正在使用Oracle 10g XE数据库和Yii 1.1.14

这是我的config/main.php

<?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'=>'Portal Online Store',
    'language'=>'en',
    'theme'=>'default',

    // preloading 'log' component
    'preload'=>array('log'),

    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
    ),

    'modules'=>array(
        // uncomment the following to enable the Gii tool

        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'bolu',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'=>array('127.0.0.1','::1'),
        ),

    ),

    // application components
    'components'=>array(
        'user'=>array(
            // enable cookie-based authentication
            'allowAutoLogin'=>true,
        ),
        // 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>',
            ),
        ),      
        // uncomment the following to use a MySQL database

        'db'=>array(
            'connectionString'=>'oci:dbname=152.116.31.148:1521/XE;charset=UTF8',
            //'emulatePrepare' => true,
            'username' => 'xxxxxxxxx',
            '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'=>'webmaster@example.com',
        'timeout'=>'900',
        'timezone'=>'Asia/Jakarta'
    ),
);

2 个答案:

答案 0 :(得分:1)

  1. 您需要刷新数据库模式,运行以下代码以便删除它(使用包含以下代码的操作创建控制器...)

    public action refreshSchema()
    {
    // Load all tables of the application in the schema
    Yii::app()->db->schema->getTables();
    // clear the cache of all loaded tables
    Yii::app()->db->schema->refresh();
    }
    
  2. 另一种简单的方法是转到运行时/缓存目录并清除所有* .bin文件,这样它就会强制创建新的缓存模式。

  3. 最后一种方法是刷新特定表的缓存

    Yii::app()->db->schema->getTable('tablename', true);
    

答案 1 :(得分:0)

问题不在Yii中。我们是Yii的新手,也是Oracle数据库的新手。更改表格后,您必须更新WWW_TAB_COLUMNS中名为WWW_TAB_CONSWWW_TABLESSQL developer (Oracle DB)的表格。如果不知道,Yii不知道数据库中的任何更改。 WWW_TAB_COLUMNS包含有关数据库中存在的所有列的信息。然后,WWW_TAB_CONS包含有关数据库中存在的所有约束的信息。最后,WWW_TABLES包含有关数据库中存在的所有表的信息。在进行CRUD操作之前,Web应用程序看起来必须首先看到这些表

相关问题