Relation already exists during rake migration

Vaibhav Rajput picture Vaibhav Rajput · Sep 26, 2012 · Viewed 15.8k times · Source

I have installed a blog engine to refinerycms which is working perfectly.

Now I have generated a migration with some table fields changes (of course not refinerycms or blog tables), but I'm getting an error:

== CreateBlogStructure: migrating ============================================
-- create_table("refinery_blog_posts", {:id=>true})
NOTICE: CREATE TABLE will create implicit sequence "refinery_blog_posts_id_seq1" for serial column "refinery_blog_posts.id"
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: relation "refinery_blog_posts" already exists
: CREATE TABLE "refinery_blog_posts" ("id" serial primary key, "title" character varying(255), "body" text, "draft" boolean, "published_at" timestamp, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Answer

Sam Ruberti picture Sam Ruberti · Jan 26, 2013

Check your db/schema.rb

You most likely have the same table being created there in addition to a migration in db/migrate/[timestamp]your_migration

You can delete the db/migrate/[timestamp]your_migration if it is a duplicate of the one found in the schema and it should work.