开发者

Changing table info with Rails migration

In my original migration, I had this:

create_table :credit_purchases do |t|
  t.co开发者_运维问答lumn :amount, :decimal, :precision => 8, :scale => 2, :null => false
  t.column :time, :datetime, :null => false
end

Which produced the following MySQL table definition:

CREATE TABLE `credit_purchases` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `amount` decimal(8,2) NOT NULL,
  `time` datetime NOT NULL,
  PRIMARY KEY (`id`),
)

When I run this, it doesn't change the definition at all:

change_column :credit_purchases, :amount, :decimal, :precision => 8, :scale => 2
change_column :credit_purchases, :time, :datetime

I'd expect the definition result to be:

CREATE TABLE `credit_purchases` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `amount` decimal(8,2) DEFAULT NULL,
  `time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
)

What do I have to do to produce the desired result? I want to avoid defining DB constraints via the migration.


Try explicitly adding :null => true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜