I am back on track .. track of writing something new here…
and this time it is Migrations .. Rails Migrations ..

As you must be knowing (u all Rails enthusiasts) that migrations allow
you to make changes to your database schema. In doing so, you also get the
facility of moving from version x to y of your database.

So this time I was required to add a column to my already existing model.
So I went ahead and did something like this …

def self.up
  add_column :media, :category_name, :string
  muvee = Media.find_by_name('whoami')
  muvee.update_attributes :category_name => 'action'

When I ran this migration, the new column got added to the table but the
migration did not update the data in the table.

I reran.. thinking I missed something but nothing happened.

After a while I came across something and added it to the migration code. This time

it did add the column along with the data.

def self.up
  add_column :media, :category_name, :string
  muvee = Media.find_by_name('whoami')
  FileType.reset_column_information # This was added ...
  muvee.update_attributes :category_name => 'action'

What ‘FileType.reset_column_information’ does is that it makes the new schema change
available to the model as it resets the column information ( w/ the information about the new column). Thus the changes become available for the new data to be inserted properly.

Hope this information helps someone out there in case such situation arises.

Cheers !!!

6 thoughts on “Migrations

  1. issacfrost says:

    Oh one more thing. How did you do that
    Possibly related posts: (automatically generated)

    * Migrations And You!
    * RoR Migration Tool

    Section? I’d love to add something like that to my blog so it can auto generate related posts. Care to explain it to me? Thanks for your time!

  2. issacfrost says:

    I’m looking for more material to add to my blog so Im surfing related blogs that have things that I haven’t gotten yet. I have scheduled some articles by other people and plan on writing some myself once I dust off my books and start reading them. I used to make applications with VB and built in databases using (tadaaa) Access. I also edited a business Information System for the university built on Access by working on the SQL. THE BAD PART IS I lost my pendrive with all my works. So I cannot go ahead and post up code and code examples like I wished.

    Hey I need you to edit or re leave that comment your link isn’t showing up! You wrote it with httpp! So go back and leave me another comment with your address.

    Oh are you using your own domain or is this a blog within wordpress?

  3. IssacFrost says:

    I added this on my article section for databases with your link back here. Hope its okay with you. If it isn’t let me know to take it down and put something else.

  4. IssacFrost says:

    Student in Computer Science. Serve as Federal Juror. And I am running the blog I have right now.

    Anyhow on to your concern. The reason most people do that is because they are afraid that Google will penalize them for duplicate content. Since I’ve studied quite a bit on SEO I can assure that won’t really happen.

    I treat articles as I would any Ezine Article, Go Article or any of those sites where you can get free articles: I post them up fully on my site and have the author credited with a link back to wherever he wishes be it his site, a blog, or anything on that matter.

    This reason is because: the reader gets to read the article in full, yet he can still visit the site/blog and read more articles by that same author. Or in some cases if the author has a business site visit there site and maybe become a client😉

  5. IssacFrost says:

    I am self hosted😉 but I don’t put any ads, I find it would dumb down my blogs purpose. I do however promote the services of DB2Go.

    Believe it or not Google does seem to penalize for duplicate content. But it has to be some extreme case of duplicate, like duplicating a site.

    Glad to see you are alive though. I was wodnering whatever happened to you. And what do you do? What do you work in?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s