yii2 - yii2如何正确指定迁移命名空间类?

标签 yii2 migrate

有人可以解释一下如何正确指定我的模块迁移命名空间吗?正如我在文档中看到的,它是:

return [
'controllerMap' => [
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationNamespaces' => [
            'app\migrations', // Common migrations for the whole application
            'module\migrations', // Migrations for the specific project's module
            'some\extension\migrations', // Migrations for the specific extension
            ],
        ],
    ],
];

但是没有说明我应该在哪个文件中写命令。我已经在 config.php 中试过了,如下所示:

    'controllerMap' => [
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationNamespaces' => [
            'app\modules\adBoard\migrations',
        ],

但是我不知道应该写哪个controller类。有人可以告诉我必须在哪个文件中指定它以及如何正确指定它吗?

最佳答案

如果你引用这个文档

Configuring Command Globally

Instead of entering the same option values every time you run the migration command, you may configure it once for all in the application configuration like shown below:

return [
     'controllerMap' => [
         'migrate' => [
             'class' => 'yii\console\controllers\MigrateController',
             'migrationTable' => 'backend_migration',
         ],
     ], ];

With the above configuration, each time you run the migration command, the backend_migration table will be used to record the migration history. You no longer need to specify it via the migrationTable command-line option.

Namespaced Migrations

Since 2.0.10 you can use namespaces for the migration classes. You can specify the list of the migration namespaces via migrationNamespaces. Using of the namespaces for migration classes allows you usage of the several source locations for the migrations. For example:

 return [
     'controllerMap' => [
         'migrate' => [
             'class' => 'yii\console\controllers\MigrateController',
             'migrationNamespaces' => [
                 'app\migrations', // Common migrations for the whole application
                 'module\migrations', // Migrations for the specific project's module
                 'some\extension\migrations', // Migrations for the specific extension
             ],
         ],
     ], ];

这个配置应该放在你的console/config/main.php

但对于命名空间迁移,请记住从 2.0.10 开始

关于yii2 - yii2如何正确指定迁移命名空间类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44773033/

相关文章:

javascript - Yii2:如何将 JSON 加载到 GridView 中?

eloquent - 如何删除yii2中的多对多关系(数据透视表)

.net - 升级应用程序时迁移用户级自定义设置

ruby-on-rails - Heroku 实例中的 Rails 4 `rake db:migrate`,引用错误

database - node.js sequelize 在迁移时没有主键

mysql - Laravel 迁移偏头痛

yii2 - 在 yii2 中使用访问控制

php - yii2 错误不在日志中

api - Yii2 Restful API - 添加新操作的示例

svn - 跨服务器迁移 Subversion 存储库