You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
StandardError: An error has occurred, this and all later migrations canceled:
=== Dangerous operation detected #strong_migrations ===
Adding a column with a non-null default blocks reads and writes while the entire table is rewritten.
Instead, add the column without a default value, then change the default.
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.1]
def up
add_column :active_storage_blobs, :service_name, :string
change_column_default :active_storage_blobs, :service_name, :local
end
def down
remove_column :active_storage_blobs, :service_name
end
end
Then backfill the existing rows in the Rails console or a separate migration with disable_ddl_transaction!.
class BackfillAddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
ActiveStorageBlob.unscoped.in_batches do |relation|
relation.update_all service_name: :local
sleep(0.01)
end
end
end
Then add the NOT NULL constraint in separate migrations.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: