0

I have 20 tables in my MySQL database. I read the Kohana documentation and learned that in order for ORM to work properly, the primary key of tables should be named 'id'.

I have created my tables before knowing this requirement and primary key are named in the format ID (eg:- UsersID). I believe, if i change the name of the primary keys then i have to reset all the references(FK) manually which is a herculean task.

I am using Workbench and is there any option available to automtically update references(FK) once i change the name of the primary key.

logeeks
  • 4,849
  • 15
  • 62
  • 93
  • if i understand correctly, do you wants to rename pkey in mysql – jmail Apr 07 '14 at 11:11
  • Might be this question can solve your problem. http://stackoverflow.com/questions/6388063/how-to-change-value-of-primary-key-and-update-foreign-key-in-the-same-time. – Chirag Bansal Apr 07 '14 at 11:17

2 Answers2

0

if I understand correctly, do you want like following as:

it's no different than altering any other column --

ALTER TABLE `pkey` CHANGE `keyfield` `keyfield2` INT(11) NOT NULL AUTO_INCREMENT 

This changes the column keyfield in table pkey to be called keyfield2 -- you have to supply the definition afterwards, as usual.

jmail
  • 5,944
  • 3
  • 21
  • 35
0

You can also configure ORM to use a field other that id as the primary key in the model:

protected $_primary_key = 'your_id';

The field used must be indexed and unique. (documented here)

This is often helpful when using Kohana/ORM with existing databases.

Carl Groner
  • 4,149
  • 1
  • 19
  • 20