PG::UndefinedTable: ERROR: relation "active_storage_blobs" does not exist
PG::UndefinedTable: ERROR: relation "active_storage_blobs" does not exist
更新应用程序Rails 5.2 到 6,更新添加了以下两个迁移:
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
end
和
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def up
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
尝试 运行 迁移在标题上出现错误。没有在网上找到任何东西,关于如何修复它有什么想法吗?
active_storage_blobs
table 还不存在。您需要先 运行:
rails active_storage:install
此命令将在 2 table 秒内添加 2 个迁移:active_storage_attachments
和 active_storage_blobs
。
这些新迁移需要 运行 在您上面的迁移之前。有一个技巧,您可以考虑手动将上面 2 个迁移的文件名中的时间戳更改为比 active_storage:install
将创建的 2 个新迁移更高的时间戳。
所有这些都排序后,运行 rake db:migrate
更新应用程序Rails 5.2 到 6,更新添加了以下两个迁移:
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
end
和
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def up
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
尝试 运行 迁移在标题上出现错误。没有在网上找到任何东西,关于如何修复它有什么想法吗?
active_storage_blobs
table 还不存在。您需要先 运行:
rails active_storage:install
此命令将在 2 table 秒内添加 2 个迁移:active_storage_attachments
和 active_storage_blobs
。
这些新迁移需要 运行 在您上面的迁移之前。有一个技巧,您可以考虑手动将上面 2 个迁移的文件名中的时间戳更改为比 active_storage:install
将创建的 2 个新迁移更高的时间戳。
所有这些都排序后,运行 rake db:migrate