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 on Rails: "ActiveRecord::StatementInvalid: Could not find table 'users' " while running unit tests

I completed the building a simple ruby on rails application tutorial and started the Building Social Features in Ruby on Rails. I am on the first stage and have created a user_friendships model. The next video starts testing the user_friendships model. After running the user_friendship_test my cmd prompt threw the error: ActiveRecord::StatementInvalid: Could not find table 'users' ActiveRecord::StatementInvalid: Could not find table 'user_friendships'

I followed along with the video and ran rake db:test:prepare

This fixed the user_friendships table error, but I was still receiving the "could not find table 'users' " error. I have a user model and my site still runs fine. I can still post, login, logout, etc.

I tried running the user_test.rb file, which worked during previous videos, and it also threw the "could not find table 'users' " error. I've also checked the test.sqlite3 file, and it is not present. I'm guessing this is only an issue while running tests because the site still works properly. I don't know what I am missing.

4 Answers

Might be a routes issues? Try running "rake routes."

Try running rake db:test:prepare. This should set up your test database. When you run your migrations, they only affect your development environment unless you tell it otherwise.

I would suggest to start with a fresh database, try rake db:drop (to drop the tables) rake db:create rake db:migrate (to create the tables) rake db:test:prepare (to create the test database)

most probably it will solve the problem

I figured this out check to make sure the devise_create_users has the .rb at the end before you rake db:migrate