简体   繁体   English

rails_admin SQLite3 :: SQLException:没有这样的列

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

I use rails_admin. 我使用rails_admin。 I have several tables, you can see all except one, when I try to look at it I get an error: 我有几个表,您可以看到除一个表以外的所有表,当我尝试查看它时出现错误:

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" =?

its my section model 它是我的部分模型


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

and its my heading model 和我的前进模式


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

How can I resolve this error? 如何解决此错误?

That's what I see when I try to view the table: 这是我尝试查看表格时看到的:


 - 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 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", force: true do |t| create_table“ sections”,强制:true | t | t.string "name" t.datetime "created_at" t.datetime "updated_at" end t.string“名称” t.datetime“ created_at” t.datetime“ updated_at”结束

If you look at your db/schema.rb you don't have a column called section_id in the headings table. 如果查看db / schema.rb,则标题表中没有名为section_id的列。 You need one otherwise "belongs_to :section" can't work. 您需要一个,否则“ belongs_to:section”将无法工作。

So you need to create that column. 因此,您需要创建该列。

rails generate migration AddSectionIdToHeading section_id:integer

rake db:migrate

cheers Steve 欢呼史蒂夫

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

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