Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:08:28+00:00 2026-05-23T08:08:28+00:00

I have updated my user migration changing the column user with username and now

  • 0

I have updated my user migration changing the column “user” with “username” and now when running

User.find_by_id(session[:user_id]) 

server outputs

SQLite3::SQLException: no such column: user: SELECT  "users".* FROM "users" WHERE "users"."id" IS NULL ORDER BY user LIMIT 1

Why it still trying ordering by “user” ??

thanks.

UPDATE:

here’s user table

create_table "users", :force => true do |t|
    t.string   "username",                                                         :null => false
    t.string   "avatar"
    t.string   "hashed_password",                                                  :null => false
    t.string   "salt",                                                             :null => false
    t.string   "mail",                                                             :null => false
    t.integer  "login_count",                   :default => 0
    t.datetime "last_login",                    :default => '2011-06-23 08:59:41'
    t.datetime "last_request_at",               :default => '2011-06-23 08:59:41'
    t.string   "user_type",                     :default => "ruolo da definire"
    t.integer  "ammonizioni",                   :default => 0
    t.integer  "numero_segnalazioni_accettate", :default => 0
    t.integer  "numero_segnalazioni_risolte",   :default => 0
    t.datetime "created_at"
    t.datetime "updated_at"

UPDATE 2: if it helps … I’m using cancan and the error come from the method “current_user” on application controller:

def current_user
  @current_user = User.find_by_id(session[:user_id]) 
end

The solution of the problem has reveaved a new one:

  def User.authenticate(user, password)
    if user = find_by_username(user)
      if user.hashed_password == encrypt_password(password, user.salt)
        user
      end
    end
  end

This worked well until I changed the migration. THe error for the first problem is repeated:

SQLite3::SQLException: no such column: user: SELECT  "users".* FROM "users" WHERE "users"."username" IS NULL ORDER BY user LIMIT 1

How should I modify this?

if user = User.find_by_username(user)

Answering to Mike:

  • yes session[:user_id] is null because I’m not logged in
  • your solution, for the second problem, produce the same error!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:08:29+00:00Added an answer on May 23, 2026 at 8:08 am

    This should work

     def current_user
          @current_user ||= User.find(session[:user_id]) if session[:user_id]
     end
    

    or alternatively,

     def current_user
          @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
     end
    

    The important point to note is that I’m checking to see that session[:user_id] is not null. If you look at your SQL error ...WHERE "users"."id" IS NULL ... it is indeed null.

    Update

    yes session[:user_id] is null because I’m not logged in

    That’s why I ended with if session[:user_id] to ensure such a session exists in the first place.

    Update #2

    To prove that .find_by_username(user.username) works and simply passing in user I just tried a test

    ruby-1.8.7-p334 :003 > User.find_by_name(User.all.last)
     => nil
    

    Of course, as expected, User.find_by_name(User.all.last.name) works 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website, which will be frequently updated. Sometimes changes happen to User
I have the following query: UPDATE lessonstatus INNER JOIN user ON lessonstatus.user_id = user.user_id
I currently use Authlogic in a web-app to handle user authentication, but have now
This is a running question that I have updated to hopefully be a little
So I've a user model and a corresponding table (users) with fields: User_id, username,
I have frequent updates to a user table that simply sets the last seen
I have a basic CRUD form that uses PageMethods to update the user details,
We have an application containing a lot of user controls that update frequently based
We have a nightly process that updates applications on a user's pc, and that
I have an alert box that displays updates processed in php to the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.