Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

I have just begun the ActiveRecord section of my course get an error when I run 'rake db:migrate.' Please help!!!

Here are the details of the error that occurs: (Sorry about the length.) By the way, Thank you!

-- create_table(:posts) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

undefined method textrake' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000004897980>/home/bob/Source/blog/hamblog/db/migrate/20150129221015_create_posts.rb:5:inblock in change' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/connection_adapters/abstract/schema_statements.rb:198:in create_table' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:649:inblock in method_missing' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:621:in block in say_with_time' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:621:insay_with_time' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:641:in method_missing' /home/bob/Source/blog/hamblog/db/migrate/20150129221015_create_posts.rb:3:inchange' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:595:in exec_migration' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:579:inblock (2 levels) in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:578:in block in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:inwith_connection' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:577:in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:752:inmigrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:991:in block in execute_migration_in_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:1037:inblock in ddl_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in block in transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:209:inwithin_new_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/transactions.rb:208:intransaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:1037:in ddl_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:990:inexecute_migration_in_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:952:in block in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:948:ineach' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:948:in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:807:inup' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/migration.rb:785:in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.1.7/lib/active_record/railties/databases.rake:34:inblock (2 levels) in <top (required)>'

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 49,047 Points

I think there's a problem in your migration file for create_posts... Could you add that migration file to your post.

Thank you for taking a look at my problem. Here's the code for the migration file:

class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :title t.textrake :body t.create :db

  t.timestamps
end

end end

Another thing that I noticed is that the test.sqlite3 file is blank. It was created with nothing in it.

Bob

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 49,047 Points

My guess is that when you generated the migration, you gave the :body attribute a datatype of :textrake; i'm guessing what you wanted was :text. Since the migration didn't go through, I think you should be able to open the migration file, change t.textrake to t.text, save the file and then run the migration. I don't think you have to rollback the migration, since it was canceled before it created anything in the database . I'm not sure that test.sqlite3 will have anything in it yet, even if the migration is a success, since that is the database file for the test environment; but, the development.sqlite3 file shouldn't be empty (however, it's not human readable and you definitely shouldn't modify it). I'm still relatively new to rails, so let me know if this helps you get any closer to solving your problem. Also, I'm not sure that you need t.create :db, but I wouldn't do anything about it until after you change the body's datatype and try running the migration again.

Clayton,

I tried your idea to see if it would fix the problem but it solve the problem. I am thinking that the table may have been created with one of the earlier failures and that could be the problem. What do you think?

Thank you!

Bob

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 49,047 Points

If this migration was the last one you ran, you could try db:rollback and with the changes mentioned above in place, save the file and run db:migrate again. You could also try creating a new migration that makes the change to the :body column. The Rails Guides advocates the latter approach in most cases; however, I think that the first approach should be fine in your situation, but I'll defer to the Rails Guides and let you decide which approach is more suitable. Here's the link to the migration guide ( check out section 5 Changing Existing Migrations ): http://guides.rubyonrails.org/active_record_migrations.html#changing-existing-migrations

Clayton,

I appreciate your information and your help. I have copied and pasted it into the file that I am keeping for future use, just in case I run into another error like this. I may have figured out the problem with this migrate not working correctly. I also may have also broken it with my method, I don't know.

I created another version of the blog under a new name and looked in the db folder and I noticed that there was a schema.rb file in it and there was not one in the original version. I learned that the problem was being caused because the original Post.rb file still existed. I deleted it and the rest of the files, ran 'rake db:create,' which worked; then 'rails generate model Post title:string body:text,' which worked; and lastly I ran 'rake db:migrate' and it worked. At least they seemed to work.

I do believe the method you described will work better for me in the future. I appreciate your help and I will let you know if my less than proper method of repair works. Thank you again!

Bob

My rather abnormal approach to the problem that I was having seems to be remedied. I just finished the first lesson of ActiveRecord and it all seems to work, at least so far.

Thanks again, Clayton!

Bob

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 49,047 Points

That's great! If you're ever having problems, RailsGuides is a good resource to check out. Here's the link to the main page if you're interested in bookmarking it: http://guides.rubyonrails.org/.

clayton