Ruby ActiveRecord 增加primary key

https://thinkwhere.wordpress.com/2009/05/09/adding-a-primary-key-id-to-table-in-rails/

def self.up
add_column :table_name, :id, :primary_key
end

def self.down
remove_column :table_name, :id
end

如果是往已存在的表中增加primary_key的话,则也会给已存在的records添加整形id。

你可能感兴趣的:(Ruby ActiveRecord 增加primary key)