Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 - how to add new column with default value via schema

Tags:

yii2

how to add new column with default value via schema? I make as this:

$this->addColumn('users', 'email_notification', Schema::TYPE_SMALLINT . ' AFTER auth_key DEFAULT 0  ');

but it's not working..

Thanks

like image 421
Hoang NK Avatar asked Feb 07 '15 03:02

Hoang NK


2 Answers

Try this, type parameter accepts ColumnSchemaBuilder as well.

$this->addColumn('users', 'email_notification', $this->smallInteger()->defaultValue(0));
like image 88
Sławomir Kania Avatar answered Sep 20 '22 12:09

Sławomir Kania


Make sure you 'use' the yii\db\Schema

use yii\db\Schema;
use yii\db\Migration;
like image 20
pszaba Avatar answered Sep 18 '22 12:09

pszaba