title: "username" IS NULL LIMIT 1
body: <p>Hello i'm not sure what the problem with this one.</p>
  
  <p>I try to implement the Omniauth-facebook on my app with devise.</p>
  
  <p>here where i saw the guide 
  <a href="https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview" rel="nofollow">https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview</a></p>
  
  <p>after trying it. it's only redirect to sign_up url.</p>
  
  <p>here my code together with devise.</p>
  
  <p><strong>student.rb</strong></p>
  
  <pre><code>class Student &lt; ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable
  
  devise :omniauthable, :omniauth_providers =&gt; [:facebook]
  attr_accessor :login
  
  validates :username,
    :uniqueness =&gt; {
     :case_sensitive =&gt; false
  },
  :format =&gt; { with: /\A[A-Za-z][A-Za-z0-9._-]{2,19}\z/ }
  
  def self.from_omniauth(auth)
   where(auth.slice(:provider, :uid)).first_or_create do |student|
    student.provider = auth.provider
    student.uid = auth.uid
    student.username = auth.info.uid
    student.email = auth.info.email
    student.firstname = auth.info.firstname
    student.lastname = auth.info.lastname
    student.password = Devise.friendly_token[0,20]
   end
  end
  
  def self.find_first_by_auth_conditions(warden_conditions)
   conditions = warden_conditions.dup
   if login = conditions.delete(:login)
     where(conditions).where(["lower(username) = :value OR lower(email) = :value",{ :value =&gt; login.downcase }]).first
   else
     where(conditions).first
   end
  end
  
  end
  </code></pre>
  
  <p><strong>students/omniauth_callbacks_controller.rb</strong></p>
  
  <pre><code>class Students::OmniauthCallbacksController &lt; Devise::OmniauthCallbacksController
    def facebook
      @student = Student.from_omniauth(request.env["omniauth.auth"])
  
      if @student.persisted?
        sign_in_and_redirect @student, :event =&gt; :authentication
        set_flash_message(:notice, :success, :kind =&gt; "Facebook") if is_navigational_format?
      else
        session["devise.facebook_data"] = request.env["omniauth.auth"]
        redirect_to new_student_registration_url
      end
    end
  end
  </code></pre>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>devise_for :students, :controllers =&gt; { :omniauth_callbacks =&gt; "students/omniauth_callbacks" }
  </code></pre>
  
  <p><strong>terminal Logs</strong></p>
  
  <pre><code>Started GET "/students/auth/facebook" for 127.0.0.1 at 2014-07-13 12:49:38 +0800
  I, [2014-07-13T12:49:38.289478 #18659]  INFO -- omniauth: (facebook) Request phase initiated.
  
  
  Started GET "/students/auth/facebook/callback?code=AQAu8HkwMJyqNZRUJ7vrD9U9Pn6MtWhNu7SYcNXiGenslAqEfzdKHKR2bfYSqRjYe3NXjWEdW4zGEIfTo_J-mpqRUfZRkN9_t2mJmn2PAqzXYPICiroyhWo2shjI2c9YzKs-0mT-ZZ7Das1WfoxQccd4_MOlwA7boi2vyxk-XLzFogDgM_1kVr58rRnA-6aSi4cdXGNdk0eM9Ic4qPa3RKpz3LFSGjLljpzsD_5RY7X8xYlbyTHIXJYg7cx0R6mAMdC4483Oyf5kAkmSyhNSRnO3rrlqGGUwG3iYMNMg4r02IUzW0MJip7Y1HJYnth7pv4M&amp;state=4582701b7f51f315b76c3efb2354e1f1e90eaec47b5294a1" for 127.0.0.1 at 2014-07-13 12:49:38 +0800
  I, [2014-07-13T12:49:38.719705 #18659]  INFO -- omniauth: (facebook) Callback phase initiated.
  Processing by Students::OmniauthCallbacksController#facebook as HTML
    Parameters: {"code"=&gt;"AQAu8HkwMJyqNZRUJ7vrD9U9Pn6MtWhNu7SYcNXiGenslAqEfzdKHKR2bfYSqRjYe3NXjWEdW4zGEIfTo_J-mpqRUfZRkN9_t2mJmn2PAqzXYPICiroyhWo2shjI2c9YzKs-0mT-ZZ7Das1WfoxQccd4_MOlwA7boi2vyxk-XLzFogDgM_1kVr58rRnA-6aSi4cdXGNdk0eM9Ic4qPa3RKpz3LFSGjLljpzsD_5RY7X8xYlbyTHIXJYg7cx0R6mAMdC4483Oyf5kAkmSyhNSRnO3rrlqGGUwG3iYMNMg4r02IUzW0MJip7Y1HJYnth7pv4M", "state"=&gt;"4582701b7f51f315b76c3efb2354e1f1e90eaec47b5294a1"}
    Student Load (0.7ms)  SELECT  "students".* FROM "students"  WHERE "students"."provider" = 'facebook' AND "students"."uid" = '10204532053849746'  ORDER BY "students"."id" ASC LIMIT 1
     (0.2ms)  BEGIN
    Student Exists (0.4ms)  SELECT  1 AS one FROM "students"  WHERE "students"."username" IS NULL LIMIT 1
     (0.2ms)  ROLLBACK
  Redirected to http://localhost:3000/students/sign_up
  Completed 302 Found in 81ms (ActiveRecord: 1.5ms)
  
  
  Started GET "/students/sign_up" for 127.0.0.1 at 2014-07-13 12:49:40 +0800
  Processing by Devise::RegistrationsController#new as HTML
    Rendered devise/shared/_links.erb (0.7ms)
    Rendered devise/registrations/new.html.erb within layouts/application (6.0ms)
    Rendered layouts/_notification.html.erb (0.1ms)
    Rendered layouts/_header.html.erb (1.2ms)
  Completed 200 OK in 44ms (Views: 42.6ms | ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>Any idea how i can solve this problem. on rails console both username with different details can create new.</p>