例如,我有上崗遷移文件:如何將db結構更改遷移到heroku postgres?
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.text :text
t.integer :ip
t.timestamps
end
end
end
並希望將其更改爲:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.text :text
t.integer :ip, :limit => 8
t.timestamps
end
end
end
請問我添加一行:
change_column :posts, :ip, :limit => 8
下面讓該文件是:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.text :text
t.integer :ip, :limit => 8
t.timestamps
change_column :posts, :ip, :limit => 8
end
end
end
然後運行heroku run rake --trace db:migrate
我無法理解遷移是如何工作的,尤其是對於生產,所以任何幫助都將不勝感激。
http://guides.rubyonrails.org/active_record_migrations.html#changing-columns對列修飾符有3.5節,但它沒有指定如何傳遞它們。
謝謝!
噢,除了最後一個例子,它會讀't.integer:ip',然後只有在下面纔會在change_column中設置限制嗎?謝謝! – Laser 2015-02-08 03:04:45