Deploying Rails App to Heroku: ERROR: relation “todo_lists” does not exist
I've been stuck on this problem for a few days. Can you guys provide some guidance to fix this and deploy the database to Heroku?
Here is part of my
Here is part of my
schema.rb
:create_table "todo_items", force: :cascade do |t| t.string "title" t.bigint "user_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.boolean "completed", default: false t.datetime "completed_at" t.bigint "todo_id", null: false t.index ["todo_id"], name: "index_todo_items_on_todo_id" t.index ["user_id"], name: "index_todo_items_on_user_id" end create_table "todos", force: :cascade do |t| t.string "title" t.bigint "user_id", null: false t.bigint "project_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["project_id"], name: "index_todos_on_project_id" t.index ["user_id"], name: "index_todos_on_user_id" end
I'm trying to deploy a new Rails 6 application to Heroku and have done the following:
-
heroku login
-
heroku create app
-
heroku addons:create heroku-postgresql:hobby-dev
-
git push heroku master
-
heroku run rails db:migrate
When I run the last command
heroku run rails db:migrate
- I get the following error messages:NOTE: I created the wrong
todo_list
reference and table at one point, then later removed them, so todo_lists
does not exist at all on my schema.Error message #1
StandardError: An error has occurred, this and all later migrations canceled: PG::UndefinedTable: ERROR: relation "todo_lists" does not exist ... /app/db/migrate/20200606053040_create_todo_items.rb:3:in `change' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `ddl_transaction' ... /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `ddl_transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1309:in `execute_migration_in_transaction'
Error message #2
Caused by: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "todo_lists" does not exist ... /app/db/migrate/20200606053040_create_todo_items.rb:3:in `change' ... /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1002:in `migrate' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `block in ddl_transaction' ... /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `ddl_transaction'
Error message #3
Caused by: PG::UndefinedTable: ERROR: relation "todo_lists" does not exist ... /app/db/migrate/20200606053040_create_todo_items.rb:3:in `change' ... /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1002:in `migrate' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `block in ddl_transaction' ... /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1361:in `ddl_transaction'
Here is part of my migrations
rails db:migrate:status
:up 20200604053157 Create todos up 20200606053040 Create todo items up 20200606235328 Add completed to todo items up 20200606235537 Add completed at to todo items up 20200608050430 Remove todo list id from todo items up 20200608050957 Drop todo list up 20200608051132 Add todo id to todo items
20200606053040_create_todo_items.rb
class CreateTodoItems < ActiveRecord::Migration[6.0] def change create_table :todo_items do |t| t.string :title t.references :user, null: false, foreign_key: true t.references :todo_list, null: false, foreign_key: true t.timestamps end end end
20200608050430_remove_todo_list_id_from_todo_items.rb
class RemoveTodoListIdFromTodoItems < ActiveRecord::Migration[6.0] def change safety_assured { remove_reference :todo_items, :todo_list, null: false, foreign_key: true } end end
20200608050957_drop_todo_list.rb
class DropTodoList < ActiveRecord::Migration[6.0] def change drop_table :todo_lists end end
20200608051132_add_todo_id_to_todo_items.rb
class AddTodoIdToTodoItems < ActiveRecord::Migration[6.0] disable_ddl_transaction! def change add_reference :todo_items, :todo, null: false, index: {algorithm: :concurrently} end end
Notifications
You’re not receiving notifications from this thread.