ActiveRecord::NoDatabaseError: local user with ID does not exist ActiveRecord::NoDatabaseError: local user with ID does not exist ruby-on-rails ruby-on-rails

ActiveRecord::NoDatabaseError: local user with ID does not exist


It seems to be Spring's problem, not the database if you're getting this error:

/Users/yad/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect': local user with ID 501 does not exist (ActiveRecord::NoDatabaseError)

in the rails root directory enter:

spring stop

it should say:

Spring stopped.

and the migration will work after that!


I am going to share what worked for me, it sounds like a joke, but it isn't.

I turned it on and off again.

What I mean by this is that I killed the Redis instance that need to run in parallel to my setup, stashed the local changes on the branch, and tried again. And it worked!

After that I killed the Unicorn server only, popped the stash to restore my local changes and restarted. And yes, it still worked.

This doesn't make any sense, I know and I apologise for not having a better explanation.

My only guess is that I might have kept the Unicorn and Redis servers running for too long (can't remember last time I shut down my Mac) and something might have gotten messed up. If that was the case then restarting the whole stack could have been the solution.

Hope this gives you, dear reader, food for thought on this mysterious error.


The error is not related to your business data. Looking at the top lines of your log...

ActiveRecord::NoDatabaseError: local user with ID 501 does not exist    from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'    from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'

... it is clear that Rails cannot connect to the database.

The local user mentioned is likely an OS user which was configured to access postgres database and its record is either deleted or corrupted.

Try to connect to your database using psql from console and see if there are any issues. The command should look something like this.

psql --host=localhost --port=5432 --username=<your postgres user> --password --dbname=koboApi_development

Since your username is not set in your database config, it probably comes from an environment variable. Check that it does contain the proper value.