【发布时间】:2015-11-18 08:15:34
【问题描述】:
我有两个模型 'Tutorial' 和 'Tutorialcategory'
class Tutorialcategory < ActiveRecord::Base
has_many :tutorials
class Tutorial < ActiveRecord::Base
belongs_to :tutorialcategory
教程与 html、rubyonrails 等多个类别相关联,其中 html 和 ruby on rails 是教程类别
以下是迁移
class CreateTutorials < ActiveRecord::Migration
def change
create_table :tutorials,force: true do |t|
t.string :title
t.text :body
t.integer :rating
t.string :videoid
t.belongs_to :tutorialcategory
t.timestamps
end
end
end
class CreateTutorialcategories < ActiveRecord::Migration
def change
create_table :tutorialcategories do |t|
t.string :title
t.timestamps null:false
end
end
end
所有教程都在索引页面上正确列出,但是当我看到类别页面时,它给了我以下错误
PG::Error: ERROR: column tutorials.tutorialcategory_id does not exist
【问题讨论】:
-
您是否记得在创建迁移后运行
rake db:migrate? -
是的,我做到了,我可以添加教程。
-
@Vikram 你检查了this 线程吗?希望能有所帮助。
标签: ruby-on-rails ruby-on-rails-3 associations