gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:48:01 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com