yii2mod / base

Yii2 application template
MIT License
53 stars 15 forks source link

yii\base\ErrorException when apply migrations #35

Closed tokiaquino closed 7 years ago

tokiaquino commented 7 years ago

What steps will reproduce the problem?

In Configuration Step 3 Apply migrations when do php yii migrate

What do you get?

PHP Warning 'yii\base\ErrorException' with message 'strncmp() expects parameter 1 to be string, array given'

in {project_path}\vendor\yiisoft\yii2\BaseYii.php:133

Stack trace:

0 {project_path}\vendor\cyberz\yii2-multipath-migrations\src\controllers\MigrationsController.php(56): yii\BaseYii::getAlias()

1 {project_path}\vendor\cyberz\yii2-multipath-migrations\src\controllers\MigrationsController.php(28): cyberz\migrations\controllers\MigrationsController->lookupMigrations()

2 {project_path}\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(155): cyberz\migrations\controllers\MigrationsController->getNewMigrations()

3 {project_path}\vendor\yiisoft\yii2\base\InlineAction.php(57): yii\console\controllers\BaseMigrateController->actionUp()

4 {project_path}\vendor\yiisoft\yii2\base\InlineAction.php(57): ::call_user_func_array:{{project_path}\vendor\yiisoft\yii2\base\InlineAction.php:57}()

5 {project_path}\vendor\yiisoft\yii2\base\Controller.php(156): yii\base\InlineAction->runWithParams()

6 {project_path}\vendor\yiisoft\yii2\console\Controller.php(128): yii\base\Controller->runAction()

7 {project_path}\vendor\yiisoft\yii2\base\Module.php(523): yii\console\Controller->runAction()

8 {project_path}\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction()

9 {project_path}\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction()

10 {project_path}\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Application->handleRequest()

11 {project_path}\yii(25): yii\base\Application->run()

12 {main}

Proposed solution

In config/console.php Add migrationPath to the $config['controllerMap']['migrate'] like below

        'migrate' => [
            'class' => 'cyberz\migrations\controllers\MigrationsController',
            'migrationLookup' => [
                '@vendor/yii2mod/yii2-cms/migrations',
                '@vendor/yii2mod/yii2-cron-log/migrations',
                '@vendor/yii2mod/yii2-user/migrations',
                '@vendor/yii2mod/yii2-comments/migrations',
                '@vendor/yii2mod/yii2-settings/migrations',
                '@yii/rbac/migrations',
            ],
            'migrationPath' => '@app/migrations'
        ],

Thats because BaseMigrateController->migrationPath default value is an array, and when we apply the migration String expected

Additional info

Q A
Yii version 2.0.12
PHP version 5.6.30
ihorchepurnyi commented 7 years ago

You need the latest version of the package, dev-master

tokiaquino commented 7 years ago

How to do that @igor-chepurnoi , some config in composer.json? I'm very new with composer and git

ihorchepurnyi commented 7 years ago

Just remove cyberz package from your project and update console.php configuration as follows:

'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => [
                '@app/migrations',
                '@vendor/yii2mod/yii2-cms/migrations',
                '@vendor/yii2mod/yii2-cron-log/migrations',
                '@vendor/yii2mod/yii2-user/migrations',
                '@vendor/yii2mod/yii2-comments/migrations',
                '@vendor/yii2mod/yii2-settings/migrations',
                '@yii/rbac/migrations',
            ],
        ],
        'fixture' => [
            'class' => 'yii\console\controllers\FixtureController',
            'namespace' => 'app\tests\fixtures',
        ],
    ],
tokiaquino commented 7 years ago

Thanks @igor-chepurnoi , i have one last question, after do the modification, i run composer update but doesn't do all updates from repository. For example this updates doesn't reflect in my project

ihorchepurnyi commented 7 years ago

Hi, @tokiaquino You can change your code manually. composer update command only update packages in the require and require-dev sections in the composer.json