Skip to content

Instantly share code, notes, and snippets.

@posulliv
Created August 1, 2012 22:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posulliv/3231183 to your computer and use it in GitHub Desktop.
Save posulliv/3231183 to your computer and use it in GitHub Desktop.
alter statements to create drupal foreign keys
-- required for foreign keys on block table (MySQL requirement)
create index module on block(module);
-- required so foreign keys can be created
alter table node_comment_statistics modify column last_comment_uid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The user ID of the latest author to post a comment on this node, from comment.uid.';
alter table block_custom modify column bid int(11) NOT NULL AUTO_INCREMENT COMMENT 'The block’s block.bid.';
alter table authmap modify column uid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'User’s users.uid.';
alter table watchdog modify column uid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The users.uid of the user who triggered the event.';
alter table history modify nid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The node.nid that was read.';
alter table history modify uid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The users.uid that read the node nid.';
alter table comment modify column uid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The users.uid who authored the comment. If set to 0, this comment was created by an anonymous user.';
alter table comment modify column nid int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The node.nid to which this comment is a reply.';
-- node_type foreign keys
alter table node add constraint fk_node_nt foreign key(type) references node_type(type);
alter table block_node_type add constraint fk_bnt_nt foreign key(type) references node_type(type);
-- node foreign keys
alter table node_access add constraint fk_na_node foreign key(nid) references node(nid);
alter table node_revision add constraint fk_nr_node foreign key(nid) references node(nid);
alter table search_node_links add constraint fk_snl_node foreign key(nid) references node(nid);
alter table taxonomy_index add constraint fk_ti_node foreign key(nid) references node(nid);
alter table node_comment_statistics add constraint fk_ncs_node foreign key(nid) references node(nid);
alter table history add constraint fk_history_node foreign key(nid) references node(nid);
alter table comment add constraint fk_comment_node foreign key(nid) references node(nid);
-- users foreign keys
alter table authmap add constraint fk_authmap_users foreign key(uid) references users(uid);
alter table shortcut_set_users add constraint fk_ssu_users foreign key(uid) references users(uid);
alter table comment add constraint fk_comment_users foreign key(uid) references users(uid);
alter table users_roles add constraint fk_ur_users foreign key(uid) references users(uid);
alter table history add constraint fk_history_users foreign key(uid) references users(uid);
alter table node_comment_statistics add constraint fk_ncs_users foreign key(last_comment_uid) references users(uid);
alter table sessions add constraint fk_sessions_users foreign key(uid) references users(uid);
alter table watchdog add constraint fk_watchdog_users foreign key(uid) references users(uid);
-- filter_format foreign keys
alter table users add constraint fk_users_ff foreign key(signature_format) references filter_format(format);
alter table filter add constraint fk_filter_ff foreign key(format) references filter_format(format);
-- block foreign keys
alter table block_custom add constraint fk_bc_block foreign key(bid) references block(bid);
alter table block_role add constraint fk_br_block foreign key(module) references block(module);
alter table block_node_type add constraint fk_bnt_block foreign key(module) references block(module);
-- role foreign keys
alter table users_roles add constraint fk_ur_role foreign key(rid) references role(rid);
alter table role_permission add constraint fk_rp_role foreign key(rid) references role(rid);
-- shortcut_set foreign keys
alter table shortcut_set_users add constraint fk_ssu_ss foreign key(set_name) references shortcut_set(set_name);
-- taxonomy_term_data foreign keys
alter table taxonomy_index add constraint fk_ti_ttd foreign key(tid) references taxonomy_term_data(tid);
alter table taxonomy_term_hierarchy add constraint fk_tth_ttd_1 foreign key(tid) references taxonomy_term_data(tid);
alter table taxonomy_term_hierarchy add constraint fk_tth_ttd_2 foreign key(parent) references taxonomy_term_data(tid);
-- taxonomy_vocabulary foreign keys
alter table taxonomy_term_data add constraint fk_ttd_tv foreign key(vid) references taxonomy_vocabulary(vid);
-- search_dataset foreign keys
alter table search_node_links add constraint fk_snl_sd foreign key(sid) references search_dataset(sid);
alter table search_index add constraint fk_si_sd foreign key(sid) references search_dataset(sid);
-- search_total foreign keys
alter table search_index add constraint fk_si_st foreign key(word) references search_total(word);
-- date_format_type foreign keys
alter table date_format_locale add constraint fk_dfl_dft foreign key(type) references date_format_type(type);
alter table date_formats add constraint fk_df_dft foreign key(type) references date_format_type(type);
-- image_styles foreign keys
alter table image_effects add constraint fk_im_is foreign key(isid) references image_styles(isid);
-- file_managed foreign keys
alter table file_usage add constraint fk_fu_fm foreign key(fid) references file_managed(fid);
-- field_config foreign keys
alter table field_config_instance add constraint fk_fci_fc foreign key(field_id) references field_config(id);
-- menu_links foreign keys
alter table shortcut_set add constraint fk_ss_ml foreign key(set_name) references menu_links(menu_name);
-- menu_router foreign keys
alter table menu_links add constraint fk_ml_mr foreign key(router_path) references menu_router(path);
-- menu_custom foreign keys
alter table menu_links add constraint fk_ml_mc foreign key(menu_name) references menu_custom(menu_name);
-- registry_file foreign keys
alter table registry add constraint fk_r_rf foreign key(filename) references registry_file(filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment