新手问题 rake db:seed 時 數據庫帶 type 字段報錯 求大神!!

akqqak47 · 2017年01月12日 · 最后由 akqqak47 回复于 2017年01月12日 · 1528 次阅读

數據庫中有張表字段是 type 結果 seed 的時候出現

xxxxxxxxxxxxxx✗ rake db:seed

schools data init.

rake aborted!

ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: '全日制'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite School.inheritance_column to use another column for that information.

/home/sog/.rvm/gems/[email protected]/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:182:in `rescue in find_sti_class'

/home/sog/.rvm/gems/[email protected]/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:175:in `find_sti_class'

/home/sog/.rvm/gems/[email protected]/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:209:in `subclass_from_attributes'

/home/sog/.rvm/gems/[email protected]/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:55:in `new'

/home/sog/.rvm/gems/[email protected]/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:33:in `create'

/home/sog/mds/mdslife_doctor/db/seeds.rb:107:in `block in <top (required)>'

/home/sog/mds/mdslife_doctor/db/seeds.rb:106:in `<top (required)>'

下面是 db/seeds.rb

puts "schools data init."

School.delete_all

CSV.foreach("db/data/longer.csv") do |row|

    School.create(name:row[0],department:row[1],address:row[2],level:row[3],remark:row[4],type:"全日制'")

end

puts "schools data finish."

实际上错误信息已经告诉你了。 type 字段已经被保留使用了。

ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: '全日制'. 
This error is raised because the column 'type' is reserved for storing the class in case of inheritance. 
1. Please rename this column if you didn't intend it to be used for storing the inheritance class
or 
2. overwrite School.inheritance_column to use another column for that information.

謝謝 我看到了 https://ruby-china.org/topics/27327 這篇帖子上有解決方法 😀 😀 十分感謝

需要 登录 后方可回复, 如果你还没有账号请 注册新账号