Phinx: How to make id field unsigned?

Created on 14 Oct 2015  路  8Comments  路  Source: cakephp/phinx

It always create id field as signed. But I am not going to have negative values there so I would like to use unsigned. I do not understand how to do that.

This is what I am doing now but I am not sure it is very elegant way

$this->table('user', ['id' => FALSE, 'primary_key' => 'id'])
    ->addColumn('id', 'integer', ['null' => TRUE, 'signed' => FALSE, 'identity' => TRUE,  'limit' => MysqlAdapter::INT_REGULAR])

Most helpful comment

FYI - This is shipping later today in Phinx 0.8.1. See #768.

All 8 comments

I agree, it's kind of weird to have signed auto-incrementing id fields. I changed the id column after the create to make it work.

$users = $this->table('users');
$users->addColumn('email', 'string', ['length' => 255])
            ->addColumn('password', 'string', ['length' => 255])
            ->addColumn('address', 'string', ['length' => 255])
            ->addTimestamps()
            ->addIndex('email', ['unique' => true])
            ->create();
$users->changeColumn('id', 'integer', ['signed' => false, 'identity' => true])->update();

@jimdoescode this looks like more elegant and clean way to do that. But I still believe there have to be an option.

Still this is not added. Shouldn't even be an option, but the default.

Agreed, just stated using phinx and discovered same problem.

I also agree with @wesleywesley to make id field unsigned by default.

Currently resorting with @jimdoescode hack, which works but shouldn't be nessecary.

IMHO it should be unsigned by default.
Unsigned ID doubles the upper limit and is recommended to use in MySQL official docs

I've implemented this in my fork here: https://github.com/lukewatts/phinx/

Just be aware I've also changed the default collation to utf8_unicode_ci in this fork, because it's better for foreign language support.
To set it back to utf8_general_ci change this line:
https://github.com/lukewatts/phinx/blob/master/src/Phinx/Db/Adapter/MysqlAdapter.php#L208

The lines to change to set the ids to unsigned by default are:
https://github.com/lukewatts/phinx/blob/master/src/Phinx/Db/Adapter/MysqlAdapter.php#L219
https://github.com/lukewatts/phinx/blob/master/src/Phinx/Db/Adapter/MysqlAdapter.php#L230

FYI - This is shipping later today in Phinx 0.8.1. See #768.

Closing for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamesTheHacker picture JamesTheHacker  路  15Comments

SergeC picture SergeC  路  13Comments

ahmarov picture ahmarov  路  27Comments

saada picture saada  路  14Comments

jeremylivingston picture jeremylivingston  路  20Comments