2

In Yii framework I used migration just like ./yiic migrate create tbl_demo it made the migration file where I entered the values for up like

<?php

class m110714_094912_tbl_demo extends CDbMigration
{
  public function up()
  {
    $this-> createTable('{{tbl_demo}}', array(
      'id' => 'pk',
      'name' => 'VARCHAR \'80\' NOT NULL',
    ))
  }

  public function down()
  {
    echo "m110714_094912_tbl_demo does not support migration down.\n";
    return false;
  }

  /*
  // Use safeUp/safeDown to do migration with transaction
  public function safeUp()
  {
  }

  public function safeDown()
  {
  }
  */
}

after entering this it is showing message like

New migration created successfully.

But whenever I am checking mysql database there is no table for tbl_demo is found. I also put all the values of up in safeup but it not made any result.Every thing is working fine but don't know why new table is not creating? Please help me

2 Answers 2

2

You should go to the command line and call yiic migrate up and it will ask you if you want to apply the tbl_demo migration and when you type in "yes" it will execute the code. The message New migration created successfully. appears when you execute yiic migrate create -something- not when you apply the migration.

If you want to apply the migration again, you should delete the row regarding "tbl_demo" migration in the "migrations" db table that yiic created to log the migrations.

Sign up to request clarification or add additional context in comments.

3 Comments

ya I have made that..Yiic migrate up and it showed messge like Migrated up successfully. But no new table is found in the database.
You haven't said what is your DB server (mysql?) I would do 'name' => 'VARCHAR(80) NOT NULL' which is the right syntax and if it doesn't help I would go to CDbConnection's createTable command and see how the SQL query is built, then dump it with echo and exit after the dump. Once you see what the query is, go try it yourself with other sql client to see if all is right with the query itself. ALSO keep in mind that the migrations use the DB config in console.php, not main.php - your console.php might point to another db?
thanks buddy it helped me.Actually I had not made connection ib console.php. I had made connection to the database in main.php. So really thank u :)
2

I just fixed this problem myself.

The answer is, the default /protected/config/console.php comes out of the box configured to use a SQLite database called testdrive.db. You have to configure it to talk to your MySQL database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.