数据迁移migration中self.down撤销外键约束的语句
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://fsjoy.blog.51cto.com/318484/89042 |
例:
class CreateLineItems < ActiveRecord::Migration def self.up create_table :line_items do |t| t.column :product_id, :integer, :null=>false t.column :order_id, :integer, :null=>false t.column :quantity, :integer, :null=>false t.column :total_price, :decimal, :null=>false, :precision => 8, :scale => 2 end execute "alter table line_items add constraint fk_line_item_products foreign key(product_id) references products(id)" execute "alter table line_items add constraint fk_line_item_orders foreign key(order_id) references orders(id)" end def self.down execute "alter table line_items drop foreign key fk_line_item_products" execute "alter table line_items drop foreign key fk_line_item_orders" drop_table :line_items end end 本文出自 “李骥平” 博客,请务必保留此出处http://fsjoy.blog.51cto.com/318484/89042 本文出自 51CTO.COM技术博客 |


fsjoy1983
博客统计信息
热门文章
最新评论
友情链接
