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 trialAya Yousef
9,658 PointsError in bin/rake db:migrate
when I run this command bin/rake db:migrate
I get this error
== 20151020021106 CreateTodoItems: migrating ================================== -- create_table(:todo_items) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "todo_items" already exists: CREATE TABLE "todo_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "todo_list_id" integer, "content" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change'
-e:1:in
<main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "todo_items" already exists: CREATE TABLE "todo_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "todo_list_id" integer, "content" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change'
-e:1:in
<main>'
SQLite3::SQLException: table "todo_items" already exists
/home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change'
-e:1:in
<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
To solve it, I tried to remove the model todo_item by using these commands
rake db:rollback
rails destroy model todo_item
rake db:drop
rake db:setup
rake db:drop RAILS_ENV=test
rake db:setup RAILS_ENV=test
Although when I tried to remake the todo_item model after removing the previous one I still get the same error!
should I reset git .. if so, how can I reset it to the previous working version: Add spec for deleting to-dos
2 Answers
Seth Reece
32,867 PointsHi aya,
Running rake db:reset should drop and recreate your database. You can also run rake db:drop db:create db:migrate. Your model doesn't really have anything to do with database migrations.
P.S. This is ok in deveopment and test, but you would want to read up on migrations for a production environment. You don't want your users emailing that they can't log in and all there todo lists are gone.
Aya Yousef
9,658 PointsThank you Seth it worked after dropping the db