0

I installed postgresql and created a database. When I run rake db:migrate though I am encountering the error below:

[newuser@Freenaut flights1percent{master}]$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreatePeople: migrating ===================================================
-- create_table(:people)
NOTICE: CREATE TABLE will create implicit sequence "people_id_seq" for serial column "people.id"
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR: relation "people" already exists
: CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp) 

This is a strange error because the error message says this table already exists. However, I know that it shouldn't as I just created the database. So what's going down wrong here?

1 Answer 1

1

This shouldn't happen unless the table does indeed exist. Could it be that you created the table as part of testing before running the migration?

I ran your create table on an 8.4 db and this is what I got:

CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp);
   NOTICE:  CREATE TABLE will create implicit sequence "people_id_seq" for serial column "people.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "people_pkey" for table "people"
CREATE TABLE

And then I ran it again after and recieved the same error message that you did:

CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp);
NOTICE:  CREATE TABLE will create implicit sequence "people_id_seq1" for serial column "people.id"
ERROR:  relation "people" already exists
Sign up to request clarification or add additional context in comments.

1 Comment

I'm using 9.0.4. But nonetheless this shouldn't happen. There are no tests being run prior to the migration. All I do is literally create the db, and run the rake. Also I ran rake db:migrate:status and it showed me that both migrations appear to be down. I don't understand what to make of this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.