当前位置: 首页 > 知识库问答 >
问题:

ActiveRecord::NodatabaseError:具有ID的本地用户不存在

葛炜
2023-03-14

开发一个只使用API的Rails应用程序来使用来自API的数据,过滤掉许多字段,然后广播我们想要公开的字段。

我的应用程序正常返回数据,但我意识到在源API级别,我们更改了我们公开的数据字段之一的数据类型。为了适应,我提交了我的工作,签出了一个新分支,运行迁移以更改数据字段的数据类型,决定对它的工作方式不满意,回滚了迁移,提交并签出了主分支。应用程序正常返回数据。但是,现在当我使用诸如.first.last等查找方法在Rails控制台中测试模型的记录时,我得到了下面的错误。他们以前工作得很好。

我环顾四周,没有看到任何关于这个特定错误的线程(它们似乎都处理为显示页面查找单个记录)--尽管这个线程和这个线程(扩展)似乎最接近。检查我正在使用的数据库上的用户会发现错误中的用户ID(“501”)不存在。

提前谢了。

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'

我肯定会拿到我的记录--它们会进入数据库:

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
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

共有1个答案

温举
2023-03-14

如果出现这个错误,这似乎是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停止

 类似资料:
  • 我创建一个简单的应用程序与用户,文章和优惠。现在用户可以创建文章并提供给该文章。所以用户有很多文章,有很多优惠,文章属于用户,有很多优惠,提供物品给用户和文章...所以我写: at用户模型: 在文章范本中: 在报价模式中,我写道: 但现在我有一个问题,如何在OffersController中创建store()函数-我尝试: 但我得到错误: 此外,我的表格代码是: 我的路线是: 如何添加报价和报价需

  • 问题内容: 我一直在寻找答案,但是找不到任何有效果的东西 在我的休息服务中,我在/ account / {id} / download下保留了一些功能,我想在SecurityConfig java文件中设置acces ROLE,只有ROLE_TOKENSAVED用户可以访问此URL。 当{id}可更改时,模式应如何显示? 我尝试了一些正则表达式模式,但没有按我希望的那样工作,这是我的一些尝试: 在

  • 当我尝试运行或调试时,android Studio 1.3.2显示为“本地路径不存在”,设备名称也没有apk文件,构建文件夹Gradle-2.4 Gradle plugin-1.3 注意:我从eclipse导入了这个项目 编辑:我解决了这个问题。。现在,新的一个是“无法在dexpath类中找到mainactivity” 但是第1类。dex和Class 2。生成dex

  • 问题内容: 如果我有两个像这样的hibernate实体: 我有一个已经存储的公司 我可以创建一个仅用其ID引用公司的人,而不是加载整个记录,例如: 它是仅保存参考还是使用更新公司? 问题答案: 是的,您可以做到。 它是否仅保存引用,还是使用name = null更新公司? 使用default ,这样,Hibernate将不执行任何操作。因此答案是:它只保存一个外键。 最有效的方法(也适用于JPA)

  • 当我点击“编辑”时,我收到此错误: 下面是< code>UsersController: 完整跟踪如下: