在线上环境中数据库配置文件添加 enableSchemaCache
和 schemaCacheDuration
,示例以下:php
'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2advanced', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'tablePrefix' => 't_', 'enableSchemaCache' => true, 'schemaCacheDuration' => 0, ], // ... ],
注意:开启这个以后,每次修改数据库结构记得要删除缓存文件!mysql
$ composer dumpautoload -o
修改入口文件 web/index.php
,禁用调试模式web
defined('YII_DEBUG') or define('YII_DEBUG', false);