I have to specify a column as unsigned in yii2 migrations .
Example migration code from manual
public function up()
{
$this->createTable('news', [
'id' => $this->primaryKey(),
'title' => $this->string()->notNull()
]);
}
From the research I have done there doesn't seem to be a method to add the unsigned capability in schema builder trait.
But is there some other way I can add unsigned attribute to the column while still making use of the schemaBuilderTrait style methods ?
For instance the $this->string()
above returns an instance of yii\db\ColumnSchemaBuilder
, but that doesn't even have a property to set unsigned/signed..
Unfortunately, some things are impossible to write with new migrations syntax.
In this case you can use string concatenation like that:
'title' => $this->string()->notNull() . ' UNSIGNED',
Alternatively you can use old syntax (backwards compatibility is observed):
use yii\db\Schema;
...
'title' => Schema::TYPE_STRING . ' NOT NULL UNSIGNED',
P.S. You can post issue on official framework repo for this problem.
Update: It's already implemented, use ->unsigned()
method. Note that you need to update framework. Thanks leitasat for information.
Just in case: they did it.
Now you can add ->unsigned()
to your definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With