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

ruby migrate error why?

so when you scaffold to create a class with some attributes, it also creates a migrate db. but is it created locally, which is why when you run server it might look in that class for model information such as Pages which points them to db migration files?? but then find nothing? until you migrate it to the server files? I'm a bit confused as to what migrate does and how a migrated db works.

This was on this https://teamtreehouse.com/library/our-first-resource

1 Answer

Derek, I'm still learning Rails too, so I apologize if this isn't the answer you are looking for. When you run the rails generate scaffold Page command, it creates a number of files in your project (so if you run that command in your local project, the files will be added to that same local project). It does create what's called a migration file in your project, but it does not actually "migrate" anything (as in, move anything from one environment to another), and it also does not execute the command needed to actually create any database table named "pages" with whatever fields you added as attributes in the scaffold command. You have to write an additional command, rails db:migrate, to actually create the database table. Running the generate scaffold command should also have created a model file (in this case, /app/models/page.rb), so I'm not sure why your program seems to be "finding nothing."

Maybe reading this RoR guide to scaffolding will help you understand things? Caution, though, this links to the Rails 3.2 docs, and you're likely running 4.2 or 5.0, so things are likely different. For example, I know with Rails 5 the command is rails db:migrate, while in previous versions it was rake db:migrate.

Anyway, hope this helps a bit, and that everything starts making sense to you soon!

On re-reading your question, I thought it might be helpful to also include a link to the official RoR guide to migrations, so you can learn what exactly migrations do. I think Rails's docs are pretty well-written, so I always check there first. Cheers.