Getting Table doesn't exist error, but the table does exist (ActiveRecord::StatementInvalid Mysql2::Error: Table doesn't exist)

Ruper

I am getting the following error when I try to access one of my pages

ActiveRecord::StatementInvalid (Mysql2::Error: Table 'p478r679_partybot.secretsanta' doesn't exist: SHOW FIELDS FROM 'secretsanta'): app/controllers/secretsantas_controller.rb:7:in `index'

But this table exists in my DB.

Just to give you a background of my problem, I wrote this application few years ago and it was working fine up until recently. When I tried to start the application with thin server, I got the following error

You have already activated rack 1.4.3, but your Gemfile requires rack 1.2.1. Using bundle exec may solve this. (Gem::LoadError)

So I approached the tech support from my hosting service for assistance. They said,

“The problem was that the rails version was not compatible with the bundler version. Now we have changed the rails version to "3.1.10" and have installed the bundler "1.2.3 ". Now your website is loading fine.The "thin" service is started in your server. The port is listening to the application. Refer the details given below.”

And they have updated all my gems for get it working. I was originally using Rails 3.0.1 and thin 1.2.7. Now I have Rails 3.1.10 and thin 1.5.1. Now the application is loading, and all the features working, except Secretsanta.

When I look at the following part of the error message closely, “SHOW FIELDS FROM secretsanta” I see the table name is “secretsanta”, should it be “secretsantas”?

I am not sure what to make of this, after all the application was working fine for the past 3 years and I am not sure why it not working after updating the gems

Here is some code snip of Secretsanta model User model and SecretsantasController.

Secretsanta.rb

   class Secretsanta < ActiveRecord::Base
     belongs_to :user
     belongs_to :gift_receiver, :class_name => "User"
     ...

User.rb

    class User < ActiveRecord::Base

      # Setup accessible (or protected) attributes for your model
      attr_accessible :first_name, :last_name, :email,
                      :password, :password_confirmation, :remember_me

      validates :first_name, :presence => true
      validates :last_name, :presence => true
      validate :should_be_invited

      # Include default devise modules. Others available are:
      # :token_authenticatable, :confirmable, :lockable and :timeoutable
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable

      has_one :potluck

      has_one :secretsanta
      has_one :gift_receiver, :through => :secretsanta

      has_many :secretsantaExclutions
      has_many :excluded, :through => :secretsantaExclutions

      has_many :discussions
      has_many :comments
      ...

secretsantas_controller.rb

    class SecretsantasController < ApplicationController
      before_filter :authenticate_user!
      def index
        @exclutionList = SecretsantaExclution.find_all_by_user_id(current_user.id)
        @event = Event.find_by_id(4)
        @rsvp = GuestList.find_by_guest(current_user.email)
        @secretsanta = Secretsanta.find_by_user_id(current_user.id) #i am getting the error at this line

      end

Please let me know if you need and additional information. Thanks for your help in advance

nbrew

I believe you were right on in your suspicion about the secretsanta table name.

Unless you've set a table_name on your secretsanta model, rails will look for a table named secretsantas. If the application was working before, I'd guess that the table actually is named secretsantas.

To list the available tables, run:

tables = ActiveRecord::Base.connection.tables

Ah, here's the problem:

'Secretsanta'.pluralize
=> "Secretsanta"

Try specifying the table name in your model:

class Secretsanta < ActiveRecord::Base
  self.table_name = "secretsantas"
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

来自分类Dev

Create if record does not exist

来自分类Dev

Select ONE random row from Table1 where id does not exist in Table2

来自分类Dev

How to get perforce to pull only files that don't exist in workspace

来自分类Dev

获取表不存在错误,但表确实存在(ActiveRecord :: StatementInvalid Mysql2 :: Error:表不存在)

来自分类Dev

pgadmin - an error has occurred, column "datconfig" does not exist

来自分类Dev

SQLite: create table and add a row if the table doesn't exist

来自分类Dev

C# - Can't use the SystemParameters, "type or namespace does not exist"

来自分类Dev

Receiving the error PG::UndefinedColumn: ERROR: column mymodels.distance does not exist when using Geocoder's near method

来自分类Dev

Hadoop fs -cp , says file does not exist?

来自分类Dev

Laravel 4 - Method [where] does not exist

来自分类Dev

Why doesn't using a ternary ?: in CoffeeScript produce an error?

来自分类Dev

PHP & MySQL - Checking if database entry does NOT exist?

来自分类Dev

CSS Table Cell doesn't become full width

来自分类Dev

ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database

来自分类Dev

Validation error message doesn't appear in View?

来自分类Dev

Django - matching query does not exist

来自分类Dev

Rails PostgreSQL:列“ table_rows”不存在(ActiveRecord :: StatementInvalid)

来自分类Dev

ActiveRecord :: StatementInvalid:Mysql :: Error:“字段列表” Ruby灯具中的未知列“ user_id”

来自分类Dev

Ember 1.12.0 instance initializer: deferReadiness method doesn't exist

来自分类Dev

Why doesn't django dumpdata include the django_migrations table?

来自分类Dev

ActiveRecord :: StatementInvalid:Mysql2 :: Error:无法删除或更新父行-Rails 4.2.6

来自分类Dev

替代Where Exist子句MySQL

来自分类Dev

Web 部署包在部署时抛出 ERROR_SITE_DOES_NOT_EXIST

来自分类Dev

Error Target clean does not exist in the project msbuild 构建delphi项目时出错

来自分类Dev

ActiveRecord::StatementInvalid: Mysql2::Error: 重命名错误

来自分类Dev

ActiveRecord::StatementInvalid: PG::InternalError: ERROR: 解析错误 - 无效几何

来自分类Dev

ActiveRecord::StatementInvalid (PG::InvalidDatetimeFormat: ERROR: 类型日期的无效输入语法:""

来自分类Dev

迁移错误 __fake__.Does Not Exist: Tag matching query does not exist

Related 相关文章

  1. 1

    #1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

  2. 2

    Create if record does not exist

  3. 3

    Select ONE random row from Table1 where id does not exist in Table2

  4. 4

    How to get perforce to pull only files that don't exist in workspace

  5. 5

    获取表不存在错误,但表确实存在(ActiveRecord :: StatementInvalid Mysql2 :: Error:表不存在)

  6. 6

    pgadmin - an error has occurred, column "datconfig" does not exist

  7. 7

    SQLite: create table and add a row if the table doesn't exist

  8. 8

    C# - Can't use the SystemParameters, "type or namespace does not exist"

  9. 9

    Receiving the error PG::UndefinedColumn: ERROR: column mymodels.distance does not exist when using Geocoder's near method

  10. 10

    Hadoop fs -cp , says file does not exist?

  11. 11

    Laravel 4 - Method [where] does not exist

  12. 12

    Why doesn't using a ternary ?: in CoffeeScript produce an error?

  13. 13

    PHP & MySQL - Checking if database entry does NOT exist?

  14. 14

    CSS Table Cell doesn't become full width

  15. 15

    ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database

  16. 16

    Validation error message doesn't appear in View?

  17. 17

    Django - matching query does not exist

  18. 18

    Rails PostgreSQL:列“ table_rows”不存在(ActiveRecord :: StatementInvalid)

  19. 19

    ActiveRecord :: StatementInvalid:Mysql :: Error:“字段列表” Ruby灯具中的未知列“ user_id”

  20. 20

    Ember 1.12.0 instance initializer: deferReadiness method doesn't exist

  21. 21

    Why doesn't django dumpdata include the django_migrations table?

  22. 22

    ActiveRecord :: StatementInvalid:Mysql2 :: Error:无法删除或更新父行-Rails 4.2.6

  23. 23

    替代Where Exist子句MySQL

  24. 24

    Web 部署包在部署时抛出 ERROR_SITE_DOES_NOT_EXIST

  25. 25

    Error Target clean does not exist in the project msbuild 构建delphi项目时出错

  26. 26

    ActiveRecord::StatementInvalid: Mysql2::Error: 重命名错误

  27. 27

    ActiveRecord::StatementInvalid: PG::InternalError: ERROR: 解析错误 - 无效几何

  28. 28

    ActiveRecord::StatementInvalid (PG::InvalidDatetimeFormat: ERROR: 类型日期的无效输入语法:""

  29. 29

    迁移错误 __fake__.Does Not Exist: Tag matching query does not exist

热门标签

归档