drupal and multiple primary key
i have defined a new content type "statetype" 开发者_JAVA百科and a cck field "state". i need state field as primary key in this table because i have another table and i need state field as foreign key. (this code and table is not drupal and i wrote it myself but related to drupal table) so i should change state field to primary key in "statetype" table but drupal have defined vid field in this table as primary key. is there any problem if i define multiple primary key (vid,state) or if remove vid primary key?
Using db fields with a business meaning as primary/foreign keys is never a good idea. You should always use some kind of id field to do this. If you don't stick to this rule you will run into trouble, as soon your business changes. Then you would have to migrate primary keys, which is a lot more work than just changing and migrating some other data.
In MySql the easiest way is to define a filed as int and auto increment. Use this id field as a foreign key. The other way round reference the nid/vid of the drupal node.
精彩评论