我对 Yii 很陌生,我已经使用 Yii 工作了 3 个星期,Yii 帮了我很多。在我的同事需要对数据库进行一些更改之前,我的应用程序运行良好。他们删除了名为 STORE_PROCESSOR
的表并创建了 2 个名为 BIG_STORE_PROCESSOR
和 SMALL_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'
),
);
最佳答案
您需要刷新您的数据库架构,运行以下代码以将其删除(使用包含以下代码的操作创建 Controller ...)
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(); }
另一种简单的方法是转到 runtime/cache 目录并删除所有 *.bin 文件,以便强制创建新的缓存架构。
最后一种方法是刷新特定表的缓存
Yii::app()->db->schema->getTable('tablename', true);
关于php - Yii 不知道我的数据库发生了变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26337718/