我正在使用最新的 Rails 和 ruby 进行新项目,我正在使用Active Storage
用于将文件(图像和视频)上传到GCP
,当我上传大约 13-18 张图像的多个文件时,上传时间太长,当我在完成后检查我的数据库时,我的record_id
is 0
?有什么不对?
class Gallery < ApplicationRecord
has_many_attached :files
end
我的画廊 ID 是主键的 UUID
这是因为这个造成的吗?
因为他们的文件上说
If you are using UUIDs instead of integers as the primary key on your models
you will need to change the column type of "record_id"
for the active_storage_attachments table in the generated migration accordingly.
我也遇到了这个:
这是因为 record_id 列是整数类型。当您尝试在其中输入 uuid 时,会发生以下情况并获得 record_id0
对于大多数附件:
2.7.0 :001 > "a2".to_i
=> 0
2.7.0 :002 > "2a".to_i
=> 2
在设置 ActiveStorage 时创建的迁移中,有一行如下所示:
t.references :record, null: false, polymorphic: true, index: false
要与 UUID 一起使用,您必须添加type: :uuid
为了明确设置外键的类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)