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
Jason Sigmon
9,776 PointsFriendship Model Error
I just finished the creating friendship model video and when I went to run rake db:migrate I got this error
Jasons-MacBook-Pro:treebook jasonsigmon$ rake db:migrate == CreateUserFriends: migrating ============================================== -- create_table(:user_friends) -> 0.0208s -- add_index(:user_friendships, [:user_id, :friend_id]) rake aborted! An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: main.user_friendships: CREATE INDEX "index_user_friendships_on_user_id_and_friend_id" ON "user_friendships" ("user_id", "friend_id")/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in initialize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:innew'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in prepare'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:inexecute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:352:inadd_index'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in block in method_missing'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:inblock in say_with_time'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in say_with_time'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:inmethod_missing'
/Users/jasonsigmon/Documents/Gnosis/treebook/db/migrate/20130724130125_create_user_friends.rb:9:in change'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:inblock (2 levels) in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:in block in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:inmigrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:incall'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in block in ddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:inddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in block in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:inup'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:inblock (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Any suggestions?
16 Answers
Jason Seifer
Treehouse Guest TeacherCan you paste the migration file here?
Jason Sigmon
9,776 Pointsclass CreateUserFriends < ActiveRecord::Migration
def change
create_table :user_friendships do |t|
t.integer :user_friends
t.integer :friend_id
t.timestamps
end
add_index :user_friendships, [:user_id, :friend_id]
end
end
Jason Seifer
Treehouse Guest TeacherTry changing the following:
t.integer :user_friends
To:
t.integer :user_id
Jason Sigmon
9,776 PointsNow I get this.
-- create_table(:user_friendships) rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "user_friendships" already exists: CREATE TABLE "user_friendships" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in initialize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:innew'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in prepare'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:inexecute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:increate_table'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in block in method_missing'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:inblock in say_with_time'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in say_with_time'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:inmethod_missing'
/Users/jasonsigmon/Documents/Gnosis/treebook/db/migrate/20130724132408_create_user_friendships.rb:3:in change'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:inblock (2 levels) in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:in block in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:inmigrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:incall'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in block in ddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:inddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in block in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:inup'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:inblock (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Jason Sigmon
9,776 PointsTop part now looks like this
class CreateUserFriends < ActiveRecord::Migration
def change
create_table :user_friendships do |t|
t.integer :user_id
t.integer :friend_id
t.timestamps
end
Jason Sigmon
9,776 PointsJason Seifer do you think I should just completely wipe the database and remigrate it all, or is something different happening?
Jason Seifer
Treehouse Guest TeacherThat sounds like a good idea, Jason Sigmon. Try doing the following:
rake db:migrate:reset
Jason Sigmon
9,776 PointsSo when I reset it. I now get this.
== CreateStatuses: migrating ================================================= -- create_table(:statuses) -> 0.0010s == CreateStatuses: migrated (0.0011s) ========================================
== DeviseCreateUsers: migrating ============================================== -- create_table(:users) -> 0.0048s -- add_index(:users, :email, {:unique=>true}) -> 0.0005s -- add_index(:users, :reset_password_token, {:unique=>true}) -> 0.0004s -- add_index(:users, :profile_name) -> 0.0004s == DeviseCreateUsers: migrated (0.0064s) =====================================
== AddUserIdToStatuses: migrating ============================================ -- add_column(:statuses, :user_id, :integer) -> 0.0007s -- add_index(:statuses, :user_id) -> 0.0005s -- remove_column(:statuses, :name) -> 0.0051s == AddUserIdToStatuses: migrated (0.0064s) ===================================
rake aborted! An error has occurred, this and all later migrations canceled:
uninitialized constant CreateUserFriends/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:230:in block in constantize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:in constantize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/core_ext/string/inflections.rb:54:inconstantize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:538:in load_migration'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:533:inmigration'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:inblock (2 levels) in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in call'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:inblock in ddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:intransaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in ddl_transaction'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:inblock in migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in each'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:inmigrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in up'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:inmigrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate:reset => db:migrate
Do you think seeing my files on Github would help?
Jason Seifer
Treehouse Guest TeacherJason Sidoryn Yes, it would, please post a link when you get some time.
Jason Sigmon
9,776 PointsJason Seifer
Treehouse Guest TeacherIt looks like you need to delete one of your migrations. This file will attempt to create that table again and then error out.
Jason Sigmon
9,776 Pointsso I tired to edit that file and I still get the same result. Should I just completely delete my migrations folder?
Jason Seifer
Treehouse Guest TeacherHi Jason Sigmon you need to actually delete one of the files, not edit it. Give that a try and let us know if it works.
Jason Sigmon
9,776 PointsDo you think I should just delete all of them. Run db reset. Then copy the migration files from project files on the video?
Jason Sigmon
9,776 PointsJason Seifer Thanks for all your help. I just downloaded the files and copied over the test, rake, and db files and it fixed the issue. Looking forward to finally proceeding :)
Jason Sigmon
9,776 Pointsonly problem I have now is its saying it can't locate 'statuses" table when I run tests. I'm guessing this is a easy fix but I can't find it in my notes.