1

Getting a PG::DuplicateTable: ERROR and can't figure out trying what is wrong.

Running via Spring preloader in process 6376
== 20170814192757 CreateRestaurants: migrating 
================================
-- create_table(:restaurants)
rake aborted!
 StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "restaurants" already exists
: CREATE TABLE "restaurants" ("id" serial primary key, "name" character 
varying, "rating" integer, "created_at" timestamp NOT NULL, "updated_at" 
timestamp NOT NULL)

Tried dropping the database and recreating it with the following.

rake db:drop db:create db:migrate
AltBrian
  • 2,392
  • 9
  • 29
  • 58
  • Do you have multiple migrations which create a `restaurants` table? – joost Aug 14 '17 at 20:51
  • Check your `db/schema.rb` file for a `create_table "restaurants"` block. The table must be created already by a previous migration. You can also check the db directly - run `rails db:reset`, then `rails db` to log into the psql console and then `\d restaurants` to see if the table exists and display what its columns, indexes, etc, are. – dave_slash_null Aug 14 '17 at 20:54
  • I dont know what I have done. I think I might have to start the project again. – AltBrian Aug 14 '17 at 21:10
  • 2
    ```rake db:drop db:create db:migrate``` is wrong you need to run ```rake db:drop && rake db:create && rake db:migrate```. – nzajt Aug 14 '17 at 21:11
  • I used [this](https://stackoverflow.com/a/27558631/5783745) solution and it worked for me – stevec Sep 26 '20 at 07:13

0 Answers0