I ran the below migration and forgot to include the default value I wanted. I'm trying to roll it back so that I can add the default and roll it forward again.
20190728151635_add_cooldown_to_skill_levels.rb
class AddCooldownToSkillLevels < ActiveRecord::Migration[5.1]
def change
add_column :skill_levels, :cooldown, :integer
end
end
All rails db:migrate and db:rollbacks are failing with the below error
$ rails db:rollback
== 20190728151635 AddCooldownToSkillLevels: reverting =========================
-- remove_column(:skill_levels, :cooldown, :integer)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "skill_levels"
And 100+ more lines ...
I've tried changing the migration to have explicit up/down methods to no avail
class AddCooldownToSkillLevels < ActiveRecord::Migration[5.1]
def up
add_column :skill_levels, :cooldown, :integer
end
def down
remove_column :skill_levels, :cooldown
end
end
I've tried adding a new migration that just adds the default value.
20190728153208_add_default_value_to_cooldown_on_skill_levels.rb
class AddDefaultValueToCooldownOnSkillLevels < ActiveRecord::Migration[5.1]
def change
change_column_default :skill_levels, :cooldown, 1
end
end
Similar error $ rails db:migrate
== 20190728153208 AddDefaultValueToCooldownOnSkillLevels: migrating ===========
-- change_column_default(:skill_levels, :cooldown, 1)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "skill_levels"
And 100+ more lines ...
I'm comfortable fixing it directly in SQL, but I'm trying to keep my migrations intact.
edit: adding output of $ rails db:migrate:status
...
up 20190727160901 Create skill levels
up 20190728004535 Create skill effects
up 20190728151635 Add cooldown to skill levels
down 20190728153208 Add default value to cooldown on skill levels
Appreciate your help.