Я застрял на этой проблеме несколько дней. Не могли бы вы дать какое-нибудь руководство, чтобы исправить это и развернуть базу данных на Heroku?
Вот часть моего 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
Я пытаюсь развернуть новый Rails 6 приложение к Heroku и сделали следующее:
heroku login
heroku create app
heroku addons:create heroku-postgresql:hobby-dev
git push heroku master
heroku run rails db:migrate
Когда я запускаю последнюю команду heroku run rails db:migrate
, я получаю следующие сообщения об ошибках:
ПРИМЕЧАНИЕ. Я создал неправильную ссылку todo_list
и таблица в какой-то момент, а затем их удалили, поэтому todo_lists
вообще не существует в моей схеме.
Сообщение об ошибке # 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'
Сообщение об ошибке # 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'
Сообщение об ошибке # 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'
Вот часть моих миграций (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
* 1057_ 20200608050957_todo_do32 * 1057_ 20200608050957_drop_do32 * 1057_20200608050957_drop_dodd * 1058_drop_todo_list * 1058_drop_todo_list * 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