Cannot Apply Migration Using Yiic Migrate

Hi, I’m new facing an issue when trying to apply database migration using Yii.

First I’m creating a new migration using this ::

./yiic migrate create tr

This gives me the following output.

Yii Migration Tool v1.0 (based on Yii v1.1.14)

Create new migration ‘/var/www/html/Trackstar/protected/migrations/m130921_101251_tr.php’? (yes|no) [no]:y

New migration created successfully.

Which shows that i’ve created a new migration.

Now i’ve added the necessary ddl in up() and the down(). Here is how it looks.

<?php

class m130921_101251_tr extends CDbMigration {

public function up() {





    //create the issue table


    &#036;this-&gt;createTable('tbl_issue', array(


        'id' =&gt; 'pk',


        'name' =&gt; 'string NOT NULL',


        'description' =&gt; 'text',


        'project_id' =&gt; 'int(11) DEFAULT NULL',


        'type_id' =&gt; 'int(11) DEFAULT NULL',


        'status_id' =&gt; 'int(11) DEFAULT NULL',


        'owner_id' =&gt; 'int(11) DEFAULT NULL',


        'requester_id' =&gt; 'int(11) DEFAULT NULL',


        'create_time' =&gt; 'datetime DEFAULT NULL',


        'create_user_id' =&gt; 'int(11) DEFAULT NULL',


        'update_time' =&gt; 'datetime DEFAULT NULL',


        'update_user_id' =&gt; 'int(11) DEFAULT NULL',


            ), 'ENGINE=InnoDB');

//create the user table

    &#036;this-&gt;createTable('tbl_user', array(


        'id' =&gt; 'pk',


        'username' =&gt; 'string NOT NULL',


        'email' =&gt; 'string NOT NULL',


        'password' =&gt; 'string NOT NULL',


        'last_login_time' =&gt; 'datetime DEFAULT NULL',


        'create_time' =&gt; 'datetime DEFAULT NULL',


        'create_user_id' =&gt; 'int(11) DEFAULT NULL',


        'update_time' =&gt; 'datetime DEFAULT NULL',


        'update_user_id' =&gt; 'int(11) DEFAULT NULL',


            ), 'ENGINE=InnoDB');











    //create the assignment table that allows for many-to-many

//relationship between projects and users

    &#036;this-&gt;createTable('tbl_project_user_assignment', array(


        'project_id' =&gt; 'int(11) NOT NULL',


        'user_id' =&gt; 'int(11) NOT NULL',


        'PRIMARY KEY (`project_id`,`user_id`)',


            ), 'ENGINE=InnoDB');

//foreign key relationships

//the tbl_issue.project_id is a reference to tbl_project.id

    &#036;this-&gt;addForeignKey(&quot;fk_issue_project&quot;, &quot;tbl_issue&quot;, &quot;project_id&quot;, &quot;tbl_project&quot;, &quot;id&quot;, &quot;CASCADE&quot;, &quot;RESTRICT&quot;);

//the tbl_issue.owner_id is a reference to tbl_user.id

    &#036;this-&gt;addForeignKey(&quot;fk_issue_owner&quot;, &quot;tbl_issue&quot;, &quot;owner_id&quot;, &quot;tbl_user&quot;, &quot;id&quot;, &quot;CASCADE&quot;, &quot;RESTRICT&quot;);

//the tbl_issue.requester_id is a reference to tbl_user.id

    &#036;this-&gt;addForeignKey(&quot;fk_issue_requester&quot;, &quot;tbl_issue&quot;, &quot;requester_id&quot;, &quot;tbl_user&quot;, &quot;id&quot;, &quot;CASCADE&quot;, &quot;RESTRICT&quot;);

//the tbl_project_user_assignment.project_id is a reference to tbl_project.id

    &#036;this-&gt;addForeignKey(&quot;fk_project_user&quot;, &quot;tbl_project_user_assignment&quot;, &quot;project_id&quot;, &quot;tbl_project&quot;, &quot;id&quot;, &quot;CASCADE&quot;, &quot;RESTRICT&quot;);

//the tbl_project_user_assignment.user_id is a reference to tbl_ user.id

    &#036;this-&gt;addForeignKey(&quot;fk_user_project&quot;, &quot;tbl_project_user_assignment&quot;, &quot;user_id&quot;, &quot;tbl_user&quot;, &quot;id&quot;, &quot;CASCADE&quot;, &quot;RESTRICT&quot;);


}





public function down() {


    &#036;this-&gt;truncateTable('tbl_project_user_assignment');


    &#036;this-&gt;truncateTable('tbl_issue');


    &#036;this-&gt;truncateTable('tbl_user');


    &#036;this-&gt;dropTable('tbl_project_user_assignment');


    &#036;this-&gt;dropTable('tbl_issue');


    &#036;this-&gt;dropTable('tbl_user');


}





/*


  // Use safeUp/safeDown to do migration with transaction


  public function safeUp()


  {


  }





  public function safeDown()


  {


  }


 */

}

Now the problem is whenever i’m trying to apply this migration using ./yiic migrate, its failing with the same error. Here is the sample output which i’m getting.

[root@localhost protected]# ./yiic migrate

Yii Migration Tool v1.0 (based on Yii v1.1.14)

Total 1 new migration to be applied:

m130921_101251_tr

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

*** applying m130921_101251_tr

PHP Error[2]: include(m130921_101251_tr.php): failed to open stream: No such file or directory

in file /var/www/html/yii/framework/YiiBase.php at line 427

#0 /var/www/html/yii/framework/YiiBase.php(427): autoload()

#1 unknown(0): autoload()

#2 /var/www/html/yii/framework/cli/commands/MigrateCommand.php(429): spl_autoload_call()

#3 /var/www/html/yii/framework/cli/commands/MigrateCommand.php(384): MigrateCommand->instantiateMigration()

#4 /var/www/html/yii/framework/cli/commands/MigrateCommand.php(109): MigrateCommand->migrateUp()

#5 unknown(0): MigrateCommand->actionUp()

#6 /var/www/html/yii/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs()

#7 /var/www/html/yii/framework/console/CConsoleCommandRunner.php(71): MigrateCommand->run()

#8 /var/www/html/yii/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run()

#9 /var/www/html/yii/framework/base/CApplication.php(180): CConsoleApplication->processRequest()

#10 /var/www/html/yii/framework/yiic.php(33): CConsoleApplication->run()

#11 /var/www/html/Trackstar/protected/yiic.php(7): require_once()

#12 /var/www/html/Trackstar/protected/yiic(4): require_once()

I can’t seem to find a solution for the above problem. I’ve been searching on google, stackoverflow, and yii forums, for relevant answers, but i haven’t found one. Please provide any help on how to solve this. I’m new to Yii so i’m still learning, and i’m loving it. But being stuck in the first steps is a real setback. Any sort of help would be much appreciated.

Thanks,

Maxx

For more clarification. I’m posting the config/console.php and config/main.php

-------------config/console.php-------------------------

<?php

// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'My Console Application',





// preloading 'log' component


'preload'=&gt;array('log'),





// application components


'components'=&gt;array(





    // uncomment the following to use a MySQL database





    'db'=&gt;array(


        'connectionString' =&gt; 'mysql:host=localhost;dbname=trackstar',


        'emulatePrepare' =&gt; true,


        'username' =&gt; 'user1',


        'password' =&gt; 'mydb389',


        'charset' =&gt; 'utf8',


    ),





    'log'=&gt;array(


        'class'=&gt;'CLogRouter',


        'routes'=&gt;array(


            array(


                'class'=&gt;'CFileLogRoute',


                'levels'=&gt;'error, warning',


            ),


        ),


    ),


),

);

---------------------end of console.php----------------------

------------------------config/main.php----------------------

<?php

// uncomment the following to define a path alias

// Yii::setPathOfAlias(‘local’,‘path/to/local-folder’);

// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'My Web Application',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


    'application.models.*',


    'application.components.*',


),





'modules'=&gt;array(


    // uncomment the following to enable the Gii tool


    /*


    'gii'=&gt;array(


        'class'=&gt;'system.gii.GiiModule',


        'password'=&gt;'Enter Your Password Here',


        // If removed, Gii defaults to localhost only. Edit carefully to taste.


        'ipFilters'=&gt;array('127.0.0.1','::1'),


    ),


    */


),





// application components


'components'=&gt;array(


    'user'=&gt;array(


        // enable cookie-based authentication


        'allowAutoLogin'=&gt;true,


    ),


    // uncomment the following to enable URLs in path-format


    /*


    'urlManager'=&gt;array(


        'urlFormat'=&gt;'path',


        'rules'=&gt;array(


            '&lt;controller:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/view',


            '&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;/&lt;id:&#092;d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


            '&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;',


        ),


    ),


    */


    // uncomment the following to use a MySQL database


    'db'=&gt;array(


        'connectionString' =&gt; 'mysql:host=localhost;dbname=trackstar',


        'emulatePrepare' =&gt; true,


        'username' =&gt; 'user1',


        'password' =&gt; 'mydb389',


        'charset' =&gt; 'utf8',


    ),


    'errorHandler'=&gt;array(


        // use 'site/error' action to display errors


        'errorAction'=&gt;'site/error',


    ),


    'log'=&gt;array(


        'class'=&gt;'CLogRouter',


        'routes'=&gt;array(


            array(


                'class'=&gt;'CFileLogRoute',


                'levels'=&gt;'error, warning',


            ),


            // uncomment the following to show log messages on web pages


            /*


            array(


                'class'=&gt;'CWebLogRoute',


            ),


            */


        ),


    ),


),





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


    // this is used in contact page


    'adminEmail'=&gt;'webmaster@example.com',


),

);

and the database

mysql> show tables

-> ;

±------------------------+

| Tables_in_trackStar |

±------------------------+

| tbl_migration |

±------------------------+

1 row in set (0.00 sec)

mysql> desc tbl_migration;

±-----------±-------------±-----±----±--------±------+

| Field | Type | Null | Key | Default | Extra |

±-----------±-------------±-----±----±--------±------+

| version | varchar(255) | NO | PRI | NULL | |

| apply_time | int(11) | YES | | NULL | |

±-----------±-------------±-----±----±--------±------+

2 rows in set (0.00 sec)

You changed the class name to:




class m130902_191945_create_issue_user_and_assignment_table ...



and it doesn’t match the filename anymore. It has too match.

Sorry, i forgot to edit that in my post. Please check the updated post. Also a sidenote, the only changes to my LAMP environment that i made was to install mysql-workbench and updated pcre/pcre-devel.

Package pcre-8.21-7.fc17.x86_64

Package pcre-devel-8.21-7.fc17.x86_64