Thomas McGoey-Smith

Hacking Up Your ActiveRecord Migration

When you’re just starting figuring out your domain model, it’s sometimes easier to modify your create table migration instead of creating new migrations.

Let’s say you originally were storing a field as a string

  t.string :some_sort_of_field

But you realized that you’re needing to store data that’s longer than 255 characters, so you decide to switch to a text type.

(Don’t know the difference between text and string this will help)

So you just edit the original migration to this:

  t.text :some_sort_of_field

But nothing will happen until you wipe out your own database and reset it.

In the command line, just run:

rake db:reset

Although this works out if you’re hacking up a brand new development database that has never been deployed, I wouldn’t recommend doing this on something that’s been deployed to production!

@tamcgoey on May 27, 2015

Enjoyed the article? Subscribe to my newsletter for more.

© Thomas McGoey-Smith (2014-2018). RSS.