在MIgrations中使用Schema Builder Trait时指定unsigned属性?

gya*_*guy 6 yii2

我必须在yii2迁移中将列指定为unsigned.
示例迁移代码来自手动

public function up()
{
    $this->createTable('news', [
        'id' => $this->primaryKey(),
        'title' => $this->string()->notNull()
    ]);
}
Run Code Online (Sandbox Code Playgroud)

从我所做的研究中,似乎没有一种方法可以在模式构建器特征中添加未签名的功能.

但是还有其他方法可以在使用schemaBuilderTrait样式方法的同时将无符号属性添加到列中吗?

例如,$this->string()上面的返回实例yii\db\ColumnSchemaBuilder,但是甚至没有设置unsigned/signed的属性.

aro*_*hev 7

不幸的是,使用新的迁移语法无法编写某些内容.

在这种情况下,您可以使用字符串连接:

'title' => $this->string()->notNull() . ' UNSIGNED',
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用旧语法(观察到向后兼容性):

use yii\db\Schema;

...

'title' => Schema::TYPE_STRING . ' NOT NULL UNSIGNED',
Run Code Online (Sandbox Code Playgroud)

PS你可以在这个问题的官方框架回购发布问题.

更新:它已经实现,使用->unsigned()方法.请注意,您需要更新框架.感谢leitasat获取信息.


lei*_*sat 5

以防万一:他们做到了

现在您可以添加->unsigned()到您的定义中。