Yii2 transition add new column to table

Using the migration feature in Yii2, I am trying to add a new named column 'authorization_key'

to the table 'users'

. My up

-function is this: My original function run

was this

 public function up()
 {
     $this->createTable( 'users',   [
         'id' => 'pk',
          'username' => 'string UNIQUE',
          'password' => 'string'
     ]); 


  }

      

and on startup ./yii migrate up

 after the ./yii migrate/create

table was created.

But after adding $this->addColumn('user', 'authorization_key'for', 'string UNIQUE');

, i.e. new up

function

public function up()
     {
         $this->createTable( 'users',   [
             'id' => 'pk',
              'username' => 'string UNIQUE',
              'password' => 'string'
         ]); 

         $this->addColumn('user', 'authorization_key'for', 'string UNIQUE');
      }

      

and I ran

 ./yii migrate up 

      

it didn't work and didn't create a new column but it was showing

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

      

How do I add new columns to a table using migration or what is the error here? Am I missing some commands here?

+3


source to share


1 answer


The created migration was marked as done (check the table migration in your database). If you want to add a new column to this table, you need to migrate and run it again, or create a new migration.



+8


source







All Articles