我创建了一个模型ruby脚本/生成模型文章(简单enuff)
这是迁移文件create_articles.rb:
def self.up create_table :articles do |t| t.column :user_id, :integer t.column :title, :string t.column :synopsis, :text, :limit => 1000 t.column :body, :text, :limit => 20000 t.column :published, :boolean, :default => false t.column :created_at, :datetime t.column :updated_at, :datetime t.column :published_at, :datetime t.column :category_id, :integer end def self.down drop_table :articles end end
当我运行rake:db migrate命令时,我收到一个错误rake中止!"未初始化的常量CreateArticles."
有谁知道为什么这个错误不断发生?
确保你的文件名和类名说的相同(除了类名是驼峰).迁移文件的内容应该类似于这样,简化它们:
#20090106022023_create_articles.rb class CreateArticles < ActiveRecord::Migration def self.up create_table :articles do |t| t.belongs_to :user, :category t.string :title t.text :synopsis, :limit => 1000 t.text :body, :limit => 20000 t.boolean :published, :default => false t.datetime :published_at t.timestamps end end def self.down drop_table :articles end end