If I don't use the annotate gem, how do I check the constrains that are on my table's columns? I can use rails console to see what columns are on which tables but I can't see the constraints like not null.
Any ActiveRecord subclass has columns method, that returns all metadata about columns for underlying table:
User.columns.find { |c| c.name == 'email' }.null
# => false
                        Without annotate, the easiest way from vim/text editor would be to look in the db/schema.rb file. This file is a culmination of all of your migrations and represents the current state of your database schema. 
It will look very similar to a migration file. Here's an example:
ActiveRecord::Schema.define(:version => 11) do
  create_table "users", :force => true do |t|
    t.string   "email", default: "", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "remember_token"
    t.datetime "remember_token_expires_at"
  end
end
As you can see on the email column, it may not be null (not null). Some other parameters may look like limit: 20 for character limits, etc. More column definitions are provided in the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With