Does in Rails making a column unique at a db level require it to become an index -



Does in Rails making a column unique at a db level require it to become an index -

if want create table column unique @ database level, require column become index?

i have column called username want unique not require index (logging in done based on email address, index).

so @ model level have added:

validates :username, presence: true, length: { maximum: 15 }, uniqueness: { case_sensitive: false }

but should within migration file? understand can add together migration file:

add_index :users, :username, unique: true

but create username index, don't need (and assume create app slower).

i using sqlite development (following hartl's tutorial adapting instructions own app). create unique requires index, wanted sure. expect because on http://api.rubyonrails.org/classes/activerecord/migration.html 'unique' nowadays add_index method.

that way create column unique in database, create unique index. how uniqueness implemented in dbs. it's set in index uniqueness can verified. you're doing right.

ruby-on-rails

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -