yii2yii2-basic-appyii-migrations

Error Running yii migrate after cloning


I'm using the basic template for Yii2. I created the project and uploaded it to github so other devs can clone and start contributing.

After cloning and running composer install, I'm getting this error when I try to run yii migrate.

λ php yii migrate
Yii Migration Tool (based on Yii v2.0.8)

Total 1 new migration to be applied:
        m160704_071418_user_table

Apply the above migration? (yes|no) [no]:yes
*** applying m160704_071418_user_table
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'm160704_071418_user_table' not found'

in C:\wamp\www\miespacio\vendor\yiisoft\yii2\console\controllers\MigrateController.php:170

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}

My question is: Is there any steps I'm missing to make this work? Any help would be appreciated, thanks.

Potentially useful information: I can create new migrations and run them just fine after cloning. The problem is running existing migrations.


Solution

  • You should create migration by yii migrate/create <migration-name> command. And don't change file name or class name of migrations.

    Example: create migration add test table

    yii migrate/create create_test_table

    After run that command, you will have a php file in @app/migrations

    Filename: m160704_110735_create_test_table.php

    Code generator:

    <?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `test_table`.
     */
    class m160704_110735_create_test_table extends Migration
    {
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('test_table', [
                'id' => $this->primaryKey(),
            ]);
        }
    
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('test_table');
        }
    }
    

    Remember: don't change filename or class name.

    Goodluck and have fun!