php addColumn yii 迁移位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12506062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:42:30  来源:igfitidea点击:

addColumn yii migration position

phpyiimigrationyii1.x

提问by dibs_ab

I want to add a column at the seventh place in the table, I am using

我想在表格的第七位添加一列,我正在使用

$this->addColumn('table_name','column_name','type'); 

adds the column at the end. Is there any way where I can mention the place to add column? Or any after column keyword to add my new column after, for exapmle, password column. I have learnt aboout migration from Yii Doc

在末尾添加列。有什么方法可以提及添加列的位置吗?或任何后列关键字添加我的新列之后,例如,密码列。我从Yii Doc学到了迁移

回答by SuVeRa

This should work!

这应该有效!

$this->addColumn('table_name', 'column_name', 'type AFTER column6'); 

examples:

例子:

$this->addColumn('tbl_posts', 'email', 'VARCHAR(150) AFTER `name` ');
$this->addColumn('tbl_posts', 'phone', 'string AFTER `email` ');

回答by gvanto

$this->addColumn('{{%user}}', 'username', 
            $this->string()->notNull()->unique()->after('id')
            );