phinx
phinx copied to clipboard
How to make primary key unsigned in an existing table?
Good morning, since as of phinx 0.13 PKs are unsigned by default, I would like to write a migration to update existing table and make their PKs unsigned, in order to preserve consistency between old and new future tables. I can't find a solution for doing this in the docs, there is a way? Thanks
https://github.com/cakephp/phinx/pull/2159 will make it possible to restore previous behavior for now
We should also add docs on how to overcome those upgrading challenges however I agree, that we need some info on that.
You'd want to use the changeColumn method . Assuming you're trying to change the default primary key that's created:
->changeColumn('id', 'integer', ['identity' => true, 'signed' => true])
Before:
mysql> SHOW COLUMNS FROM foo;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int unsigned | NO | PRI | NULL | auto_increment |
+-------+--------------+------+-----+---------+----------------+
1 rows in set (0.02 sec)
After:
mysql> SHOW COLUMNS FROM foo;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
+-------+--------------+------+-----+---------+----------------+
1 rows in set (0.01 sec)
@dereuromark Do you have a set place in mind to put this info? Just in the changelog for the next release that has feature flags?
We might also want to add the details in docs and from release notes more like link to it.
I guess add a note to it in the link I posted for this? I don't know another place that'd really fit.