DataMapper 模型的 FasterCSV 导入器 - 未插入行
我有一个模型(称为 Test):
property :id, Serial
property :title, String, :length => 255, :required => true
property :description, String, :length => 255, :required => true
property :brand, String, :length => 255, :required => true
property :link, String, :length => 255, :required => true
property :image_link, String, :length => 255, :required => true
property :price, String, :length => 255, :required => true
property :condition, String, :length => 255, :required => true
property :product_type, String, :length => 255, :required => true
从制表符分隔文件导入数据
我正在使用 FasterCSV、 FasterCSV.foreach("test.txt", {:headers => true, :quote_char=>'"', : col_sep =>'/t'}) do |row_data|
row_data = Test.first_or_new(
'title' => :title,
'description' => :supplier,
'brand' => :brand,
'link' => :link,
'image_link' => :image_link,
'price' => :price,
'condition' => :condition,
'product_type' => :product_type
)
row_data.save
end
当我运行导入程序时,没有出现任何错误。
我是否缺少一些明显的内容?并且字段名称与我的文件中的标题相同。
I have a model (called Test):
property :id, Serial
property :title, String, :length => 255, :required => true
property :description, String, :length => 255, :required => true
property :brand, String, :length => 255, :required => true
property :link, String, :length => 255, :required => true
property :image_link, String, :length => 255, :required => true
property :price, String, :length => 255, :required => true
property :condition, String, :length => 255, :required => true
property :product_type, String, :length => 255, :required => true
I am importing data from a tab delimited file, using FasterCSV,
FasterCSV.foreach("test.txt", {:headers => true, :quote_char=>'"', :col_sep =>'/t'}) do |row_data|
row_data = Test.first_or_new(
'title' => :title,
'description' => :supplier,
'brand' => :brand,
'link' => :link,
'image_link' => :image_link,
'price' => :price,
'condition' => :condition,
'product_type' => :product_type
)
row_data.save
end
No errors appear, when I run the importer. Nothing appears inserted in SQLite table.
Am i missing something obvious? (The table exists within the target database, and the field names are the same as the headers from my file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2014/11/19 更新:FasterCSV 已被删除。现在应该使用 Ruby 标准库 CSV。只需将所有出现的
FasterCSV
替换为CSV
有两个问题,我猜您
这应该工作得更好:
Update 2014/11/19: FasterCSV has been removed. Ruby standard library CSV should now be used intead. Just replace all occurrences of
FasterCSV
withCSV
There's two problem i guess
This should work better: