Can someone explain me please what the difference between the next things?
self.up
and up
contains the code that is ran by migrations when you do rake db:migrate
. self.up
is an older version of up
. I'm not sure when they introduced this but until 3.0, they were using self.up
.
self.down
and down
should contain the code that reverses the effect of the up
methods. so if you created a table on up
, you should drop that table on down
. These methods are called when running rake db:rollback
.
There's actually a new method on migrations called change
which is usually used if it's easy for rails to determine the opposite of what you're doing like creating tables.
def self.up
is a class method (you can send it to the class: Klass.up
), def up
is a normal method (you can send it to an object). Same for down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With