`
lfx_cool
  • 浏览: 66040 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

migration foreign key

阅读更多
# db/migrate/6_add_foreign_key.rb
class AddForeignKey < ActiveRecord::Migration
  def self.up
    execute "ALTER TABLE bees ADD CONSTRAINT beehive_id_fkey FOREIGN KEY
(beehive_id) REFERENCES beehives (id);"
  end

  def self.down
    execute "ALTER TABLE bees DROP CONSTRAINT beehive_id_fkey;"
  end
end


class AddForeignKey < ActiveRecord::Migration
  def self.up
    execute "ALTER TABLE user_notes ADD CONSTRAINT creator_id_fkey FOREIGN KEY  (creator_id) REFERENCES users (id);"
  end

  def self.down
    execute "ALTER TABLE user_notes DROP CONSTRAINT creator_id_fkey;"
  end
end
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics