簡體   English   中英

rails_admin SQLite3 :: SQLException:沒有這樣的列

[英]rails_admin SQLite3::SQLException: no such column

我使用rails_admin。 我有幾個表,您可以看到除一個表以外的所有表,當我嘗試查看它時出現錯誤:

Showing /home/barmaley/.rvm/gems/ruby-2.1.1/gems/rails_admin-0.6.2/app/views/rails_admin/main/index.html.haml where line #135 raised: 

SQLite3 :: SQLException: no such column: headings.section_id: SELECT "headings". * FROM "headings" WHERE "headings". "Section_id" =?

它是我的部分模型


    class Section < ActiveRecord::Base
  has_many :headings
  searchable do
  text :name
    end
end

和我的前進模式


class Heading < ActiveRecord::Base
  belongs_to :section
  searchable do
    text :name
    text :address
    text :phone
  end
end

如何解決此錯誤?

這是我嘗試查看表格時看到的:


 - if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {set: (params[:set].to_i - 1)} : {}))
%td.other.left= link_to "...", @other_left_link, class: 'pjax'
- properties.map{ |property| property.bind(:object, object) }.each do |property|
- value = property.pretty_value
%td{class: "#{property.css_class} #{property.type_css_class}", title: strip_tags(value.to_s)}= value
- if @other_right_link ||= other_right && index_path(params.merge(set: (params[:set].to_i + 1)))
%td.other.right= link_to "...", @other_right_link, class: 'pjax'
schema.rb
 create_table "headings", force: true do |t| t.string "name" t.string "address" t.integer "phone" t.integer "sec" t.datetime "created_at" t.datetime "updated_at" end 

\n\n

create_table“ sections”,強制:true | t | t.string“名稱” t.datetime“ created_at” t.datetime“ updated_at”結束

如果查看db / schema.rb,則標題表中沒有名為section_id的列。 您需要一個,否則“ belongs_to:section”將無法工作。

因此,您需要創建該列。

rails generate migration AddSectionIdToHeading section_id:integer

rake db:migrate

歡呼史蒂夫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM