yiidatabase-migrationyii-migrations

Create a column with primary key using migrations


I am using migrations in Yii to create a new column with. My code works fine however, I am unsure how to set a primary key?

This is a part from my migration file:

public function up()
{
    $this->addColumn(
        'competition_prizes',
        'prize_id',
        'INT(11) UNSIGNED NOT NULL FIRST',
    );

    $this->addPrimaryKey('PK1', 'competition_prizes', 'prize_id');
}

I don't know, how to make competition_prizes column the primary key.


Solution

  • This is working now - did the following:

    $this->addColumn(
        'competition_prizes',
        'prize_id',
        'INT(11) UNSIGNED NOT NULL AUTO_INCREMENT primary key FIRST'
    );