简体   繁体   English

SQLite3 :: SQLException:Rails 4.2.6中没有这样的列

[英]SQLite3::SQLException : no such column in rails 4.2.6

I am facing this SQLite exception error when running my application: 运行我的应用程序时,我遇到此SQLite异常错误:

SQLite3::SQLException at /admin SQLite3 :: SQLException在/ admin

no such column: subscription_plan.name 没有这样的列:subscription_plan.name

This is the controller code, I am facing error: 这是控制器代码,我面临错误:

def dashboard
  @number = {
      :month => Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plan.name = ?', Time.zone.now.beginning_of_month, 0, 'month']).count,
      :year => Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plan.name = ?', Time.zone.now.beginning_of_month, 0, 'year']).count
    }
end

This is Subscription model with relation: 这是具有以下关系的订阅模型:

class Subscription < ActiveRecord::Base
  belongs_to :subscription_plan
end

There is no subscription_plan model in my application, but the data to this table is populated through seeds.rb file. 我的应用程序中没有subscription_plan模型,但此表中的数据是通过seed.rb文件填充的。 As shown in the controller, 'month', 'year' are some of the names in subscription_plan table. 如控制器中所示,“ month”,“ year”是subscription_plan表中的一些名称。

It is working fine with Rails 3.2, i don't know why it's not working with 4.2.6. 它可以在Rails 3.2上正常工作,我不知道为什么它不能在4.2.6下工作。 Please help. 请帮忙。

您需要提供条件中的表名而不是关联名,请尝试

Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plans.name = ?', Time.zone.now.beginning_of_month, 0, 'month'])

你可以试试这个吗?

Subscription.includes(:subscription_plan).where(["subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plans.name = ?", Time.zone.now.beginning_of_month, 0, 'month']).references(:subscription_plans)

您无需在where子句中引用订阅,请注意复数subscription_plans.name ,并且从power中获得的注释就可以正确地添加references(:subscription_plans)

Subscription.includes(:subscription_plan).where(['created_at > ? AND amount > ? AND subscription_plans.name = ?, Time.zone.now.beginning_of_month, 0, 'month']).references(:subscription_plans).count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM