It seems that there is currently no way to change the column type that belongs to a table's primary key. I'd like to be able to make my primary key a BIGINT, VARCHAR, or a BIGSERIAL (in Postgres), but this doesn't appear to be possible.
The docs explain how to specify an alternate primary key here: http://docs.phinx.org/en/latest/migrations.html#creating-a-table under the part that starts:
To specify an alternate primary key
@shadowhand That only explains how to change the name of the primary key. I am looking to change the type of the primary key field.
@jeremylivingston sure it does... you can specify which column is the primary key, and the column definition can be any type supported by Phinx.
Okay, I will try that out. I feel like that could maybe be a bit clearer in the docs, possibly show an example demonstrating this behavior.
@shadowhand after performing the instructions in the documentation, console shows an error: Column already exists: 1060 Duplicate column name. @jeremylivingston works for you?
@gigante Did you specify id: false to make sure that no key was automatically added?
@shadowhand just works! thanks for the quickly response!
@shadowhand But... for my case, the type is biginteger and this option not set auto_increment
@gigante as the docs say:
$table = $this->table('mytable', array('id' => false, 'primary_key' => 'id'));
$table->addColumn('id', 'biginteger')
@shadowhand but not set this column with auto_increment. How I set auto_increment in this column (in your example)?
@gigante 'identity' => true
edit: wrong parameter
@shadowhand like this?
$table = $this->table('myTable', array('id' => false, 'primary_key' => 'myID', 'identity' => true));
$table->addColumn('myID', 'biginteger')
doesn't works =/
@gigante no, like this:
$table = $this->table('myTable', array('id' => false, 'primary_key' => 'myID'));
$table->addColumn('myID', 'biginteger', array('identity' => true))
@shadowhand, showed an error:
'identity' is not a valid column option
My phinx version is 0.4.1
@gigante, if you're on 0.4.1 you should see the folllwing on Phinx\Db\Table\Column line 428:
$validOptions = array('limit', 'length', 'default', 'null', 'precision', 'scale', 'after', 'update', 'comment', 'signed', 'properties', 'identity');
if you see that, then the above error is not possible. if you dont see that, then you are not on 0.4.1
@temperedvision, I have installed via composer. The version of composer may be connected with master branch. This branch still without this identity attribute. Vide link (line 428):
https://github.com/robmorgan/phinx/blob/master/src/Phinx/Db/Table/Column.php
Your reference is the 0.4.x-dev branch
ah yes, quite right, that change is only currently in the dev branch. That will need to wait for @shadowhand or @robmorgan to release that change into master.
I already have a table with primary key 'id' and I need to change it (drop primary key, drop column id, add primary key(type). I can`t find this nor in docs nor in code
I have the same issue as @Crusader4Christ... Looks like you can't do that with the Phinx API. :(
i think this is still unsolved, but duplicate as https://github.com/cakephp/phinx/issues/335
Most helpful comment
@gigante as the docs say: