任何人都可以帮我解决这个错误。
Mysql2::Error: Unknown column 'projects.company_id' in 'where clause': SELECT `projects`.* FROM `projects` WHERE `projects`.`company_id` = 2 ORDER BY position ASC
Rendered project/index.html.erb within layouts/application (22.4ms)
Completed 500 Internal Server Error in 106ms (ActiveRecord: 89.3ms)
ActionView::Template::Error (Mysql2::Error: Unknown column 'projects.company_id' in 'where clause': SELECT `projects`.* FROM `projects` WHERE `projects`.`company_id` = 2 ORDER BY position ASC):
12: <th> Actions </th>
13: </tr>
14:
15: <%= @projects.each do |project| %>
16: <tr>
17: <td><%= project.company.name if project.company %></td>
18: <td><%= project.name %></td>
app/views/project/index.html.erb:15:in `_app_views_project_index_html_erb__831754569244709537_70147764435580'
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (8.2ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.5ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (58.5ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (1.0ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (1.1ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (44.4ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (98.5ms)
答案 0 :(得分:1)
我的猜测是你只需要将company_id字段添加到Project模型中。
rails generate migration AddCompanyIdToProject company_id:integer:index
rake db:migrate
答案 1 :(得分:0)
确保Project
表格中包含company_id
列
rails generate migration AddCompanyIdToProject company:references
rake db:migrate