【发布时间】:2018-05-31 10:22:59
【问题描述】:
我正在尝试在 Rails 5.2 中使用 Active Storage。我发现我应该在迁移中创建类型为file 的字段,但是我有一个错误:
$ rdm
Running via Spring preloader in process 40193
== 20171217191942 CreateDishes: migrating
=====================================
-- create_table(:dishes)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `file' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x00007fd56e297750>
/Users/alder/Projects/_apps/service_exchange/rails-backend/db/migrate/20171217191942_create_dishes.rb:6:in `block in change'
/Users/alder/Projects/_apps/service_exchange/rails-backend/db/migrate/20171217191942_create_dishes.rb:3:in `change'
-e:1:in `<main>'
迁移:
class CreateDishes < ActiveRecord::Migration[5.2]
def change
create_table :dishes do |t|
t.string :name, index: true
t.string :description
t.file :image
t.timestamps
end
end
end
我试图创建字符串字段,但它不起作用。
在official docs 中找不到任何相关信息
我已经迁移到活动存储并且我通过了 ok
【问题讨论】:
-
我很确定 Rails 迁移中没有这种数据类型“文件”,请尝试使用 f.string
-
所以,是的,我使用的正是那个链接。如果你制作字符串字段,它会在稍后显示类型不匹配。
-
迁移继承自哪个类?确保它是最新的迁移版本,以便在 ActiveRecord 中选择新的列类型,
ActiveRecord::Migration[5.2]
标签: ruby-on-rails ruby ruby-on-rails-5 rails-activestorage ruby-on-rails-5.2