Yii2:迁移不适用

时间:2020-02-29 11:00:55

标签: yii2 database-migration

我运行./yii migrate并获得

No new migrations found. Your system is up-to-date.

我已经安装了Yii2-usuario,并且第一次运行./yii migrate时,所有迁移都被正确应用:

Yii Migration Tool (based on Yii v2.0.32)

Total 12 new migrations to be applied:
    Da\User\Migration\m000000_000001_create_user_table
    Da\User\Migration\m000000_000002_create_profile_table
    Da\User\Migration\m000000_000003_create_social_account_table
    Da\User\Migration\m000000_000004_create_token_table
    Da\User\Migration\m000000_000005_add_last_login_at
    Da\User\Migration\m000000_000006_add_two_factor_fields
    Da\User\Migration\m000000_000007_enable_password_expiration
    Da\User\Migration\m000000_000008_add_last_login_ip
    Da\User\Migration\m000000_000009_add_gdpr_consent_fields
    m140506_102106_rbac_init
    m170907_052038_rbac_add_index_on_auth_assignment_user_id
    m180523_151638_rbac_updates_indexes_without_prefix

Apply the above migrations? (yes|no) [no]:yes

但是./migrations找不到我在./yii migrate进行的迁移:

m20200228_000000_user.php

文件以开头,并且可以正常工作:

use yii\db\Migration;

class m20200228_000000_user extends Migration
{
    public function safeUp()
...

./config/web.php中进行了配置:

'controllerMap' => [
        'migrate' => [
            'class' => \yii\console\controllers\MigrateController::class,
            'migrationPath' => [
                '@app/migrations',
                '@yii/rbac/migrations', // Just in case you forgot to run it on console (see next note)
            ],
            'migrationNamespaces' => [
                'Da\User\Migration',
            ],
        ],
    ],
    ...

This SO question无济于事,因为一般的迁移似乎在这里起作用。

这是怎么回事?为什么根本找不到我的迁移?

1 个答案:

答案 0 :(得分:0)

找到了。

迁移文件的名称错误,例如m20200228_000000_user.php

名称格式为mYYMMDD_XXXXXX.php

我指定了一个四位数的年份。