yii2-如何通过模式添加具有默认值的新列

yii2-如何通过模式添加具有默认值的新列,yii2,Yii2,如何通过模式添加具有默认值的新列? 我这样做: $this->addColumn('users', 'email_notification', Schema::TYPE_SMALLINT . ' AFTER auth_key DEFAULT 0 '); 但它不起作用 谢谢请确保“使用”yii\db\Schema use yii\db\Schema; use yii\db\Migration; 我做到了,这对我来说很有用 $this->addColumn(“{{%tbl_name}},

如何通过模式添加具有默认值的新列? 我这样做:

$this->addColumn('users', 'email_notification', Schema::TYPE_SMALLINT . ' AFTER auth_key DEFAULT 0  ');
但它不起作用


谢谢

请确保“使用”yii\db\Schema

use yii\db\Schema;
use yii\db\Migration;

我做到了,这对我来说很有用


$this->addColumn(“{{%tbl_name}},'field_name',Schema::TYPE_INTEGER.”(11)默认值1)

试试这个,
类型
参数也接受
ColumnSchemaBuilder

$this->addColumn('users', 'email_notification', $this->smallInteger()->defaultValue(0));

对于新版本,您可以执行以下操作:$this->addColumn('table_name','column_name',$this->tinyInteger()“默认值0”);