Advertisement
kotvalera83

Codeigniter migration FOREIGN KEY

Nov 18th, 2013
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. class Migration_Add_f_k_user_friends extends CI_Migration {
  2.  
  3.     public function __construct()
  4.     {
  5.         $this->load->database();
  6.     }
  7.  
  8.     public function up() {
  9.         $this->db->query('ALTER TABLE friends
  10.                             ADD CONSTRAINT fk_UserFriends
  11.                             FOREIGN KEY (user_id)
  12.                             REFERENCES user(id)');
  13.         $this->db->query('ALTER TABLE friends
  14.                             ADD CONSTRAINT fk_FriendsUser
  15.                             FOREIGN KEY (friend_id)
  16.                             REFERENCES user(id)');
  17.     }
  18.  
  19.     public function down() {
  20.         $this->db->query('ALTER TABLE friends
  21.                             DROP FOREIGN KEY fk_UserFriends');
  22.         $this->db->query('ALTER TABLE friends
  23.                             DROP FOREIGN KEY fk_FriendsUser');
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement