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])
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.
Most helpful comment
FYI - This is shipping later today in Phinx 0.8.1. See #768.