DB Rake:Fail

So I come to the part where I do

ruby script/generate model Page

part of the book. I realize that much has changed in 3 years in the Ruby on Rails world. I do what any newb does when they’re stuck, I turn to search. ┬áThe command is

rails generate model Page

and whah-lah. Output appears on the terminal screen that something has automagically taken place. It can make you giddy. I have to laugh at this stuff, pros will look at this reaction and laugh. I think it’s simply awesome.

I move on and update the project/db/migrate/version_create_pages.rb file so that it has some info to insert as a record into my newly created table.

Page.create(:title => "Find A Gamer Home",
:permalink => "welcome-page",
:body => "Welcome to Find A Gamer")

in the self.up method. Save.

Shoot over to command line…

rake db:migrate

Thinks for a second and nothing seems to happen. The command line has let me down. I try again. Same result. Huh. You’d think it would change right? Just typing in the same command nothing happens, same result, strange.

Turn to search. Find some info on version numbers. Check database table, nothing new. I use

rails generate migration

don’t do that. It creates a blank migration.rb type file. Database does nothing. I end up deleting file.

I then try

rake db:migrate VERSION=<insert version number>

from <version number>_create_pages.rb file. and….BAM! some promising output appears on screen saying

create_table (:pages)



The above syntax is not verbatim, but you get the idea. Oh, the create_table part, yeah, I ended up dropping my database table with a command I shouldn’t have used. Good times.

Now, I thought rails db:migrate would do the trick without a version number, but I’ll go this route for now. Go with what works, right?

Leave a Reply

Your email address will not be published. Required fields are marked *