开发仅API的Rails应用程序以使用来自API的数据,过滤掉许多字段,然后广播我们要公开的字段。
我的应用程序正常返回数据,但是我意识到在源API级别上,我们更改了要公开的数据字段之一的数据类型。为了适应,我提交了工作, checkout 了新的分支,进行了迁移以更改数据字段的数据类型,决定我对它的工作方式不满意,回滚了迁移,提交并 checkout 了master分支。该应用程序正常返回数据。但是,现在,当我使用findert方法(例如.first
,.last
等)在Rails Console中测试模型的记录时,出现以下错误。他们以前工作得很好。
我环顾四周,还没有看到关于此特定错误的任何线程(它们似乎都与查找显示页面的单个记录有关)-尽管this和this线程(按扩展名)似乎最接近。并且检查我正在使用的数据库上的用户表明错误中的用户ID(“501”)不存在。
我做了什么,我需要怎么做才能再次调用查找器方法?我是否需要创建数据库错误中引用的用户? (为什么不是我总是用来连接数据库的默认用户?错误中的用户ID是从哪里来的呢?甚至有关系吗?)
ps-如果相关,我根据this线程使用rake db:rollback
回滚了我的迁移。
提前致谢。
Rails控制台
.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'
我肯定会得到我的记录-它们正在进入数据库:
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 | {}
来自我的架构的
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
我的数据库。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
最佳答案
这似乎是Spring的问题,如果出现此错误,不是数据库:
/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)
在rails根目录中输入:
spring stop
它应该说:
Spring stopped.
迁移将在那之后进行!
关于ruby-on-rails - ActiveRecord::NoDatabaseError:具有ID的本地用户不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38224560/