Take the 2-minute tour ×

In rails i have amigration to alter production data to fit new validation rules, There are several things wrong so i have 2 different migrations (they could be one but still two aspects that run separately ) one fails because the other validation is not met and vice versa

the validation is new in the model like

 validates_uniqueness_of :job_id , :scope => [:day, :time, :user_id , :overtime, :comments] , :message => "Duplicate Entry, Please check your data"
 validates_uniqueness_of :job_id , :scope => [:day, :user_id, :comments] , :message => "Has 2 Entires for same job on same day with same comment"

is one kind that is completely new and the other just changed from 24 to 8 and added the overtime bit

  validates_numericality_of :time, :greater_than => 0, :less_than_or_equal_to => 8
  validates_numericality_of :overtime, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 16

i tried re ordering the migrations and i got the reverse result.

is there a way other than updating the database first then updating this file to bypass that? or is that what i should be doing?

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

in rails 2:


in rails 3:

object.save(:validate => false)

These methods will bypass any and all validations on the object, so be careful!

share|improve this answer
i assume there is there anyway to make it bypass only some validation. just chekcing –  loosecannon Feb 15 '11 at 21:27
does that work for object.save! also –  loosecannon Feb 15 '11 at 21:33
The difference of using a hash is important here. The first one will not work in Rails 2. –  Max Woolf Nov 16 '12 at 13:42
add comment

Hey I know this is an old question and is already answered, but based on your comment I thought I would leave my two cents.

There is no way in Rails 2 or 3 to turn a single validation on or off. However, we use population tasks extensively in our projects so we have a small workaround for the same.

It's a little tedious if you want to do it for every single validation, but generally the one's you want to 'turn off' for a bit are few and far between.

class FooModel < ActiveRecord::Base

  validates_uniqueness_of :foo_name, :unless => :dont_check_foo_name
  attr_accessor :dont_check_foo_name


If you follow a strong naming convention, when you create an object, you can simple set the appropriate dont_check_*validation_name* to true and it will by-pass the validation.

Also, for your second comment, the following:


work in the same way.

And of-course the conditional validation I mentioned works on both as well.

share|improve this answer
hmm interesting. Im no longer working on whatever it was that required that, but i like that idea. –  loosecannon Oct 18 '12 at 19:03
add comment

Your Answer


