祖先db:迁移 [英] Ancestry db:migrate
问题描述
我试图安装Ancestry gem,但是我遇到了 rake db:migrate
的问题。
I am trying to install the Ancestry gem but I am having problems with rake db:migrate
.
我正在遵循Ancestry github页面上的说明。在我完成 rails g迁移后,add_ancestry_to_message ancestry:string
我正在编辑迁移文件(在railcast#262后面):
I am following the instructions on the Ancestry github page. After I have done rails g migration add_ancestry_to_message ancestry:string
I am editing the migration file (following railcast #262) to be:
class AddAncestryToMessage < ActiveRecord::Migration
def self.up
add_column :messages, :ancestry, :string
add_index :messages, :ancestry
end
def self.down
remove_index :messages, :ancestry
remove_column :messages, :ancestry
end
end
当我运行 rake db:migrate
时出现以下错误:
When I then run rake db:migrate
I am getting the following error:
== AddAncestryToMessage: migrating ===========================================
-- add_column(:messages, :ancestry, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: Shipmgr: ALTER TABLE "Message" ADD "ancestry" varchar(255)
Tasks: TOP => db:migrate
我已经在新创建的rails应用程序和现有的rails应用程序上尝试了这个,但是我我仍然无法得到这个工作。有人对这个问题有任何建议吗?
I have tried this on a newly created rails app and on an existing rails app but I am still unable to get this to work. Does anyone have any advice on this issue?
推荐答案
您应该尝试将迁移类名称更改为复数(表格)消息':
You should try changing the migration class name to the pluralized (table) form 'Messages':
class AddAncestryToMessages < ActiveRecord::Migration
或者更准确地说,将迁移生成器命令更改为:
or, more accurately, change the migration generator command to:
rails g migration add_ancestry_to_messages ancestry:string
这篇关于祖先db:迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!