【发布时间】:2015-08-21 11:51:37
【问题描述】:
我尝试将csv 文件导入Mysql。 ID id 从 0 开始。导入时显示duplicate entry。有什么解决办法吗?
我的迁移文件是
class CreateActors < ActiveRecord::Migration
def change
create_table :actors do |t|
t.string :title
t.float :rating
t.string :place
t.string :address
t.string :special
t.string :amount
t.string :phone
end
end
end
id默认作为主键
我的 csv 文件显示为
id title rating place address amount phone
0 . . . . . .
1 . . . . . .
导入时出现此错误
ERROR 1062: 1062: Duplicate entry '1' for key 'PRIMARY'
我该如何解决这个问题?
【问题讨论】:
-
如果文件有重复值,需要导入到临时表。删除重复项,然后添加到主表
-
它是主键,从0开始。它显示重复条目
-
您能告诉我们主键是如何定义的吗?表上已经有条目了吗?您的主键示例?
-
id是主键,从0开始到30结束。它由31个条目组成。
-
表格是空的?
标签: mysql ruby-on-rails database primary-key