我有以下 Rails 迁移:
create_table :articles do |t|
t.integer :user_id, :allow_null => false
t.integer :genre_id, :allow_null => false
t.string :url, :limit => 255, :allow_null => false
t.string :title, :limit => 60, :allow_null => false
t.text :summary, :limit => 350, :allow_null => false
t.integer :votes_count, :default => 0
t.datetime :published_at, :default => nil
t.timestamps
end
首先在模型中验证所有“NOT NULL”的字段,所以我想知道我是否需要在迁移中使用allow_null?我不确定“NOT NULL”给数据库带来了什么好处(如果有的话)。