Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Developing an API-only Rails app to consume data from an API, filter out a number of the fields, and then broadcast fields we want public.

My app was returning data normally, but I realized that on the source API level, we changed the data type for one of the fields of data we're exposing. To accommodate, I committed my work, checked out a new branch, ran a migrations to change a data field's data type, decided I wasn't happy with how it worked, rolled back the migration, committed, and checkout out the master branch. The app is returning data as normal. However, now when I test my model's records in Rails Console using finder methods like .first, .last, etc., I get the error below. They were working fine before.

I've looked around and haven't seen any threads on this particular error (they all seem to deal with finding individual records for the show page) - although this, and this thread (by extension) seem closest. And checking the users on the db I'm using shows that the user ID ("501") in the error is not present.

What did I do and what do I need to do so that I can call finder methods again? Do I need to create that user referenced in the error in my db? (and why is it not the default user that I always use to connect to my db? Where did that user ID in the error come from? Does it even matter?)

ps - in case it's relevant, I used rake db:rollback to rollback my migration as per this thread.

Thanks in advance.

Rails Console

.2.1 :001 > KoboApi.first 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'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-postgis-adapter-3.1.4/lib/active_record/connection_adapters/postgis_adapter.rb:51:in `initialize'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-postgis-adapter-3.1.4/lib/active_record/connection_adapters/postgis/create_connection.rb:37:in `new'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-postgis-adapter-3.1.4/lib/active_record/connection_adapters/postgis/create_connection.rb:37:in `postgis_connection'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'     from /Users/toby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'     from /Users/toby/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection' ... 13 levels...     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'     from /Users/toby/code/projects/koboApi-broker/bin/rails:9:in `<top (required)>'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `block in load'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'     from /Users/toby/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in `load'     from /Users/toby/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'     from /Users/toby/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' 

I'm definitely getting my records - they're coming into the database:

Rails dbconsole

koboApi_development=# select * from kobo_apis limit 1;   id  | lemurs_quantity | month_and_year | _geolocation | lemur_category | location_admin1 | location_admin2 | record_id | sighting_month | sighting_year ------+-----------------+----------------+--------------+----------------+-----------------+-----------------+-----------+----------------+---------------  1365 |               1 |                |              | I_dont_remembe | antsiranana     | diana           |   1234567 | no_response    | 2013 (1 row)  koboApi_development=# \du                              List of roles  Role name |                   Attributes                   | Member of -----------+------------------------------------------------+-----------  [user]    | Superuser, Create role, Create DB, Replication | {} 

from my schema

ActiveRecord::Schema.define(version: 20160705203507) do    # These are extensions that must be enabled in order to support this database   enable_extension "plpgsql"   enable_extension "postgis"    create_table "kobo_apis", force: :cascade do |t|     t.integer "lemurs_quantity"     t.date    "month_and_year"     t.text    "_geolocation"     t.text    "lemur_category"     t.string  "location_admin1"     t.string  "location_admin2"     t.integer "record_id"     t.string  "sighting_month"     t.string  "sighting_year"   end    create_table "my_spatial_table", force: :cascade do |t|     t.geography "polygon_data", limit: {:srid=>4326, :type=>"polygon", :geographic=>true}   end  end 

My database.yml

development:   adapter: postgis   encoding: unicode   postgis_extension: postgis      # default is postgis   postgis_schema: public          # default is public   schema_search_path: public,postgis   database: koboApi_development   pool: 5  test:   adapter: postgresql   encoding: unicode   database: koboApi_test   pool: 5  production:   adapter: postgresql   encoding: unicode   database: koboApi_production   pool: 5 
like image 613
Mugshep Avatar asked Jul 06 '16 12:07

Mugshep


1 Answers

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!

like image 84
0bserver07 Avatar answered Sep 21 '22 13:09

0bserver07