草庐IT

mysql - Rails Mysql 适配器尝试查询没有支持表的抽象模型类

coder 2023-10-11 原文

我有一个模型类“Abtest”,它继承自一个没有支持表的抽象基类“ModBase”。当调用 Abtest.new 时,即使在 ModBase 类中我有“self.abstract_class = true”,我也会收到以下错误。我做错了什么?

class ModBase < ActiveRecord::Base
  self.abstract_class = true

class Abtest < ModBase

ActiveRecord::StatementInvalid (Mysql::Error: Table 'mydb.mod_bases' doesn't exist: SHOW FIELDS FROM `mod_bases`):
  activerecord (3.1.0) lib/active_record/connection_adapters/mysql_adapter.rb:435:in `query'
  activerecord (3.1.0) lib/active_record/connection_adapters/mysql_adapter.rb:435:in `execute'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract_adapter.rb:244:in `log'
  activesupport (3.1.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
  activerecord (3.1.0) lib/active_record/connection_adapters/mysql_adapter.rb:435:in `execute'
  activerecord (3.1.0) lib/active_record/connection_adapters/mysql_adapter.rb:636:in `columns'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `initialize'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `initialize'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:112:in `call'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:112:in `default'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:112:in `[]'
  activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:112:in `initialize'
  activerecord (3.1.0) lib/active_record/base.rb:717:in `call'
  activerecord (3.1.0) lib/active_record/base.rb:717:in `default'
  activerecord (3.1.0) lib/active_record/base.rb:717:in `[]'
  activerecord (3.1.0) lib/active_record/base.rb:717:in `column_defaults'
  activerecord (3.1.0) lib/active_record/persistence.rb:327:in `attributes_from_column_definition'
  activerecord (3.1.0) lib/active_record/locking/optimistic.rb:69:in `attributes_from_column_definition'
  activerecord (3.1.0) lib/active_record/base.rb:1544:in `initialize'
  app/models/abtest.rb:89:in `new'

最佳答案

这是 3.1.0 中的一个 Rails 错误。 https://github.com/rails/rails/issues/558

我已经升级到 3.1.11,错误再也没有发生。

关于mysql - Rails Mysql 适配器尝试查询没有支持表的抽象模型类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15455687/

有关mysql - Rails Mysql 适配器尝试查询没有支持表的抽象模型类的更多相关文章

  1. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  2. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  3. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  4. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  5. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  6. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  7. 没有类的 Ruby 方法? - 2

    大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow

  8. ruby-on-rails - Rails 3,嵌套资源,没有路由匹配 [PUT] - 2

    我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle

  9. ruby-on-rails - 有没有办法为 CarrierWave/Fog 设置上传进度指示器? - 2

    我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r

  10. ruby - 没有类方法获取 Ruby 类名 - 2

    如何在Ruby中获取BasicObject实例的类名?例如,假设我有这个:classMyObjectSystem我怎样才能使这段代码成功?编辑:我发现Object的实例方法class被定义为returnrb_class_real(CLASS_OF(obj));。有什么方法可以从Ruby中使用它? 最佳答案 我花了一些时间研究irb并想出了这个:classBasicObjectdefclassklass=class这将为任何从BasicObject继承的对象提供一个#class您可以调用的方法。编辑评论中要求的进一步解释:假设你有对象

随机推荐