Ruby on rails rake db:迁移错误错误参数数(5个代表4个)
这是我的迁移文件:Ruby on rails rake db:迁移错误错误参数数(5个代表4个),ruby-on-rails,migration,Ruby On Rails,Migration,这是我的迁移文件: class AddSeoMetaInfoToArticles < ActiveRecord::Migration def self.up add_column :articles, :seo_title, :string, { :default => "", :null => false } add_column :articles, :seo_description, :string, { :default => "", :nul
class AddSeoMetaInfoToArticles < ActiveRecord::Migration
def self.up
add_column :articles, :seo_title, :string, { :default => "", :null => false }
add_column :articles, :seo_description, :string, { :default => "", :null => false }
add_column :articles, :seo_keywords, :string, :string, { :default => "", :null => false }
end
def self.down
remove_column :articles, :seo_keywords
remove_column :articles, :seo_description
remove_column :articles, :seo_title
end
end
我对rails比较陌生,不确定自己做错了什么。这是Rails 3.0.9,如果有区别,则为Postgres db。您在这一行中两次给出
:string
参数:
add_column :articles, :seo_keywords, :string, :string, { :default => "", :null => false }
has:string
两次,因此最终传递的是5个参数,而不是4个
您可能还想考虑用“代码>更改< /代码>”编写迁移。
class AddSeoMetaInfoToArticles < ActiveRecord::Migration
def change
change_table :articles do |t|
t.string :seo_title, :default => "", :null => false
t.string :seo_description, :default => "", :null => false
t.string :seo_keywords, :default => "", :null => false
end
end
end
class AddSeoMetaInfoToArticles“”,:null=>false
t、 字符串:seo\u description,:default=>“”,:null=>false
t、 字符串:seo_关键字,:default=>“”,:null=>false
结束
结束
结束
我觉得这对眼睛更容易。它还有一个优点,您可以传递:bulk=>true tochange\u table
,这将把所有3列添加合并到1个alter table语句中,这通常要快得多
这两种方法当然都有效。/facepalm有时你只需要另一双眼睛来检查它。
add_column :articles, :seo_keywords, :string, :string, { :default => "", :null => false }
class AddSeoMetaInfoToArticles < ActiveRecord::Migration
def change
change_table :articles do |t|
t.string :seo_title, :default => "", :null => false
t.string :seo_description, :default => "", :null => false
t.string :seo_keywords, :default => "", :null => false
end
end
end