迁移/升级中的异常'yii \ base \ UnknownPropertyException'

时间:2018-10-05 12:39:35

标签: yii yii2 migration database-migration yii2-advanced-app

我想使用yii2-forms extension,但在迁移时遇到问题。

这是迁移过程中的错误。

C:\xampp\htdocs\SEPreport>yii migrate/up --migrationPath=@vendor/pceuropa/yii2-forms/migrations
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request::enableCsrfValidation'

in C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\base\Component.php:209

Stack trace:
#0 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\BaseYii.php(546): yii\base\Component->__set('enableCsrfValid...', false)
#1 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\base\BaseObject.php(107): yii\BaseYii::configure(Object(yii\console\Request), Array)
#2 [internal function]: yii\base\BaseObject->__construct(Array)
#3 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\di\Container.php(383): ReflectionClass->newInstanceArgs(Array)
#4 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\\console\\Req...', Array, Array)
#5 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\BaseYii.php(349): yii\di\Container->get('yii\\console\\Req...', Array, Array)
#6 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\di\ServiceLocator.php(137): yii\BaseYii::createObject(Array)
#7 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\base\Module.php(742): yii\di\ServiceLocator->get('request', true)
#8 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\console\Application.php(219): yii\base\Module->get('request')
#9 C:\xampp\htdocs\SEPreport\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->getRequest()
#10 C:\xampp\htdocs\SEPreport\yii(27): yii\base\Application->run()
#11 {main}

,而且我在前端后端中设置了enableCsrfValidation

'components' => [
        'request' => [
            'enableCsrfValidation' => false, // I set it to true too
            'enableCookieValidation' => false,
        ],
]

请帮助我。解决该怎么办?

1 个答案:

答案 0 :(得分:1)

如果将特定于Web的设置放在consolecommon配置文件中,则可能会出现此类错误。控制台Request没有enableCsrfValidation属性,因此引发了yii\base\UnknownPropertyException异常。

如果要配置特定于Web的设置,则应在backend/config/main.php和/或frontend/config/main.php中进行设置。