打印

[一般问题] 关于数据迁移的问题

关于数据迁移的问题

需要在数据库中添加一个字段
我先运行ruby script/generate migration add_price
然后打开迁移任务的源文件,修改其中的up()方法,想表products中添加price字段。down()方法删除这个字段
class AddPrice < ActiveRecord::Migration
 def self.up
  add_column :products, :decimal, :precision =>8, :scale=>2, :default=>0
 end

 def self.down
  remove_column :products, :price
 end
end

运行数据迁移:
rake db:migrate

add_column :products, :decimal, :precision =>8, :scale=>2, :default=>0
rake aborted!
You have a nil obiect when you didn't expect it!
You might have expexted an instance of Array.
The error occurred while evaluating nil.[]
请问有啥解决方案?

[ 本帖最后由 ppdai 于 2007-11-5 23:55 编辑 ]
本帖最近评分记录
  • drive2me R币 +2 鼓励。 2007-11-6 17:21

TOP



[ 本帖最后由 ppdai 于 2007-11-5 23:51 编辑 ]

TOP

看不见你的图呀。
Flying Piggy...! 
天地人合一!

TOP



class AddPrice < ActiveRecord::Migration
  def self.up
    add_column :products, :decimal, :precision =>8, :scale=>2, :default=>0
  end

  def self.down
    remove_column :products, :price
  end
end


看不到楼主的图,我就猜一下吧,根据楼主贴出来的代码,我认为出错的地方在
add_column这个方法
add_column "表名", "字段名", "数据类型", "初始化值"
所以楼主尝试修改成
add_column :products, :price, :decimal, :precision => 8, :scale => 2, :default => 0
试试看
本帖最近评分记录
  • drive2me R币 +2 谢谢! 2007-11-6 17:21

TOP

已经解决 谢谢

TOP

你是怎么解决的?

你是怎么解决的?

TOP

2008-08-29 11:04 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html) @38.103.63.60