Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
rake db:migrate - migrate fails due to 'create table'
I made an error when creating the scaffold and had to go back to amend it.
Now, when I try to migrate the database (whether generally, test or development), I get an error. This is because the migration is trying to create a table that already exists,
todo_lists. The error looks like:
SQLite3::SQLException: table "todo_lists" already exists: CREATE TABLE "todo_lists" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
Looking in the migration file, in the
migration folder, I can see that the code does create a table.
class CreateTodoLists < ActiveRecord::Migration def change create_table :todo_lists do |t| t.string :title t.text :description t.timestamps null: false end end end
The schema looks similar:
ActiveRecord::Schema.define(version: 20150330151920) do create_table "todo_lists", force: :cascade do |t| t.string "title" t.string "string" t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false end end
In short, I don't really now what to do to get out of this so any help would be gratefully received.
Jason Seifer 's help would be great!
Trying to run the server gives an error when trying to access
localhost:3000`, that says that the solution is to run:bin/rake db:migrate RAILS_ENV=development``` which is where I ended up above.
Maciej Czuchnowski36,437 Points
You normally shouldn't mess with migrations once they are generated, but let's make an exception.
1) Go through every single migration file you have in your db/migrate folder. Make sure that none of the code is duplicated. It is possible that one of the files creates the same table or column as some other file, which will return an error.
2) Go to console and do, in this order:
rake db:create and
rake db:migrate. This will destroy the whole database and try to recreate it form your migration files. If this gives you the same errors, go back to point 1).
3) Read about migrations and how they work and how to use them
If the above doe snot help, please post a link to your github repo which contains the whole project.