"PG DuplicateTable: Error Relation "Products" already exists"- Heroku db:migrate attempt
10,302
Go to Heroku rails console and drop the products (given the they don't contain any data) table by running:
ActiveRecord::Migration.drop_table(:products)
and rerun the migration.
Or just remove the migration file that creates products table from db/migration
This will work as well.
Author by
Alb
Apparently, this user prefers to keep an air of mystery about them. Yes, that's what I'm going for.
Updated on July 19, 2022Comments
-
Alb almost 2 years
Rails rookie attempting to migrate DB to heroku. Excuse the juiciness of this error message but I figure it may be important to include it all. I have no idea why this is happening or what it means. I have only one products table in my schema and one create products migration.
Migrating to CreateProducts (20140804010848) == 20140804010848 CreateProducts: migrating =================================== -- create_table(:products) PG::DuplicateTable: ERROR: relation "products" already exists : CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "price" float, "description" text, "image" character varying(255), "color" character varying(255), "created_at" timestamp, "updated_at" timestamp) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: PG::DuplicateTable: ERROR: relation "products" already exists : CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "price" float, "description" text, "image" character varying(255), "color" character varying(255), "created_at" timestamp, "updated_at" timestamp) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing' /app/db/migrate/20140804010848_create_products.rb:3:in `change' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `block in ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/transactions.rb:208:in `transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `ddl_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
-
Alb over 9 yearsAm I going to be dropping something here that I might want?
-
neo over 9 yearsif this is a new deployment, then you're good, but if you have existing Products, then it'll erase them and you'll have to recreate them, also check edits.
-
Alb over 9 yearsI believe that I already do have them, which is why I got the error, but I don't understand what I did to make it create another duplicate table.
-
neo over 9 yearsbut do you have any data in your products table?
-
Alb over 9 yearsin my schema create_table "products", force: true do |t| t.string "name" t.float "price" t.text "description" t.string "image" t.string "color" t.datetime "created_at" t.datetime "updated_at" t.integer "product_id" end
-
neo over 9 yearsthats not it, on heroku rails console run Product.all.count if it = 0 then you don't have any data in your products table.
-
Alb over 9 yearsI have no products yet, they are to be added by admin, just plugging bogus ones in for display/logic testing. Does this mean its safe to kill this table
-
Alb over 9 yearsI removed create_products from migrations and re-ran heroku run rake db:migrate, and got the same error. ?
-
neo over 9 yearsLet us continue this discussion in chat.