I'm trying to accomplish the fairly simple feat of changing the default value for one of the columns from my Blog
table. I have the following migration:
class UpdateBlogFields < ActiveRecord::Migration[5.2]
def change
change_column :blogs, :freebie_type, :string, default: "None"
end
end
Fairly simple, but I'm getting the following error when I run rake db:migrate
:
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "blogs"
I get this error any time I try to change or remove a column, but not when adding one.
My schema looks like this:
create_table "blogs", force: :cascade do |t|
t.string "title"
t.string "teaser"
t.text "body"
t.string "category", default: "General"
t.string "linked_module"
t.boolean "published", default: false
t.datetime "published_on"
t.integer "user_id"
t.integer "image_id"
t.integer "pdf_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.string "cta_read_more", default: "Read More"
t.string "cta_pdf", default: "Get My Free PDF"
t.string "cta_video", default: "Watch the Video"
t.string "convertkit_data_form_toggle"
t.string "convertkit_href"
t.integer "pin_image_id"
t.string "data_pin_description"
t.string "freebie_filename"
t.string "video_link"
t.string "freebie_type", default: "File"
t.string "freebie_description"
t.integer "comments_count"
t.integer "subcategory_id"
t.boolean "affiliate_links", default: true
t.boolean "approved", default: false
t.boolean "submitted", default: false
t.index ["image_id"], name: "index_blogs_on_image_id"
t.index ["pdf_id"], name: "index_blogs_on_pdf_id"
t.index ["pin_image_id"], name: "index_blogs_on_pin_image_id"
t.index ["slug"], name: "index_blogs_on_slug", unique: true
t.index ["subcategory_id"], name: "index_blogs_on_subcategory_id"
t.index ["user_id"], name: "index_blogs_on_user_id"
end
It seems that this might be an SQLite thing, because this post and this one seem to be having a similar problem. However, neither post involves an actual answer. Has anyone successfully gotten rid of this?