ActiveRecord迁移主键

时间:2015-07-30 13:45:39

标签: ruby-on-rails activerecord

我有以下迁移:

ggplot(GO, aes(x = d1, y = order(d2), fill = factor(d1))) +
  geom_bar(stat = "identity"‌​, position = "identity", width = 0.6)
  1. 如何将第一行中的id定义为主键?
  2. 如何在其中一列中设置两个属性,例如,is_archived默认值为0且它也不能为空

1 个答案:

答案 0 :(得分:1)

如文件中所述:A primary key column called id will also be added implicitly, as it's the default primary key for all Active Record models...
您可以将参数传递给列,如下所示:

is_archived, default: 0, null: false

此处提供更多信息:http://guides.rubyonrails.org/active_record_migrations.html