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
.
精彩评论