Hi in my development build using sqlite3, I specified email in my Account model to be a unique index as shown below, so why it the db happy adding the same emails? this type of insert should fail! class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.string :email, :null=>false, :limit=>60 t.index :email, :unique=>true I know about ''validates_uniqueness_of :email'', but this check happen at the rails level, I wanted also something at the db level. I know sqlite3 supports unique indexing, so what''s wrong? -- Kind Regards, Rajinder Yadav -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 13, 2010, at 9:08 AM, Rajinder Yadav wrote:> Hi in my development build using sqlite3, I specified email in my > Account model to be a unique index as shown below, so why it the db > happy adding the same emails? this type of insert should fail! > > class CreateAccounts < ActiveRecord::Migration > def self.up > create_table :accounts do |t| > t.string :email, :null=>false, :limit=>60 > t.index :email, :unique=>true >create_table.... ... end add_index :accounts, :email, :unique => true The "t.index" only works for change_table()....> I know about ''validates_uniqueness_of :email'', but this check happen > at the rails level, I wanted also something at the db level. I know > sqlite3 supports unique indexing, so what''s wrong? > > -- > Kind Regards, > Rajinder Yadav > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom wrote:> > On Mar 13, 2010, at 9:08 AM, Rajinder Yadav wrote: > >> Hi in my development build using sqlite3, I specified email in my >> Account model to be a unique index as shown below, so why it the db >> happy adding the same emails? this type of insert should fail! >> >> class CreateAccounts < ActiveRecord::Migration >> def self.up >> create_table :accounts do |t| >> t.string :email, :null=>false, :limit=>60 >> t.index :email, :unique=>true >> > > create_table.... > ... > end > > add_index :accounts, :email, :unique => true > > The "t.index" only works for change_table()....Thank Philip for the explanation, this works =)> >> I know about ''validates_uniqueness_of :email'', but this check happen >> at the rails level, I wanted also something at the db level. I know >> sqlite3 supports unique indexing, so what''s wrong? >> >> -- >> Kind Regards, >> Rajinder Yadav >> >> ---- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.