{"action":"created","issue":{"url":"https://api.github.com/repos/robmorgan/phinx/issues/842","repository_url":"https://api.github.com/repos/robmorgan/phinx","labels_url":"https://api.github.com/repos/robmorgan/phinx/issues/842/labels{/name}","comments_url":"https://api.github.com/repos/robmorgan/phinx/issues/842/comments","events_url":"https://api.github.com/repos/robmorgan/phinx/issues/842/events","html_url":"https://github.com/robmorgan/phinx/issues/842","id":155574780,"number":842,"title":"Change Primary Key Constraint","user":{"login":"travy","id":4945102,"avatar_url":"https://avatars.githubusercontent.com/u/4945102?v=3","gravatar_id":"","url":"https://api.github.com/users/travy","html_url":"https://github.com/travy","followers_url":"https://api.github.com/users/travy/followers","following_url":"https://api.github.com/users/travy/following{/other_user}","gists_url":"https://api.github.com/users/travy/gists{/gist_id}","starred_url":"https://api.github.com/users/travy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travy/subscriptions","organizations_url":"https://api.github.com/users/travy/orgs","repos_url":"https://api.github.com/users/travy/repos","events_url":"https://api.github.com/users/travy/events{/privacy}","received_events_url":"https://api.github.com/users/travy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-18T18:50:10Z","updated_at":"2016-05-31T11:09:38Z","closed_at":null,"body":"Is there a way to change the primary key constraint in phinx without dropping the table?  In other-words, lets say you have a table that uses the default primary_key of 'id' and later on you realized that it would be better to change the primary key.  Is there a way to do so without manually inserting all entries into a new table, dropping the old one and then renaming the new table.\r\n\r\nI didn't notice any means for doing this within the documentation and have already tried the following techniques:\r\n\r\n1)  Change on table call\r\n\r\n```\r\n$assetsDocuments = $this->table('assets_documents', [\r\n    'id' => false,\r\n    'primary_key' => [\r\n        'asset_id', 'document_id'\r\n    ]\r\n])->save();  //  I've also tried with update\r\n```\r\n\r\n2)  Dropping the id column\r\n\r\n```\r\n//  fails obviously do to constraint, was just a blind attempt\r\n$assetsDocuments->removeColumn('id')->update();\r\n```\r\n\r\n3)  Calling addPrimaryKey(array)\r\n\r\n```\r\n//  This doesn't seem to do anything on SQL Server 2008\r\n$assetsDocumets->addPrimaryKey(['asset_id', 'document_id'])->update();\r\n```\r\n\r\nI'm early in in the development process so I was fine with just dropping the table and creating a new one with the correct primary_key values but I thought this might be a useful feature to have, if not already available.  Or good to have in the docs if it is possible."},"comment":{"url":"https://api.github.com/repos/robmorgan/phinx/issues/comments/222658485","html_url":"https://github.com/robmorgan/phinx/issues/842#issuecomment-222658485","issue_url":"https://api.github.com/repos/robmorgan/phinx/issues/842","id":222658485,"user":{"login":"rquadling","id":12801,"avatar_url":"https://avatars.githubusercontent.com/u/12801?v=3","gravatar_id":"","url":"https://api.github.com/users/rquadling","html_url":"https://github.com/rquadling","followers_url":"https://api.github.com/users/rquadling/followers","following_url":"https://api.github.com/users/rquadling/following{/other_user}","gists_url":"https://api.github.com/users/rquadling/gists{/gist_id}","starred_url":"https://api.github.com/users/rquadling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rquadling/subscriptions","organizations_url":"https://api.github.com/users/rquadling/orgs","repos_url":"https://api.github.com/users/rquadling/repos","events_url":"https://api.github.com/users/rquadling/events{/privacy}","received_events_url":"https://api.github.com/users/rquadling/received_events","type":"User","site_admin":false},"created_at":"2016-05-31T11:09:38Z","updated_at":"2016-05-31T11:09:38Z","body":"Note that for mysql with an InnoDB table, a clustered index determines the physical row ordering. In essence/general, the order of the rows is controlled by the primary index, or by various rules if a primary index does not exist.\r\n\r\nChanging the primary key has to involve a physical reconstruction of the table.\r\n\r\nhttps://dev.mysql.com/doc/refman/5.5/en/innodb-index-types.html\r\n\r\n"}}
{"actor":{"display_login":"rquadling"}}