1

使用 MySQL 数据库,我想导入一个 13 列和 120 行的 csv 文件。我正在尝试将它们上传到表格中。

这是我的命令:

mysql> load data local infile 'restaurants.csv' 
       into table restaurants_restaurant fields        
       terminated by ',' enclosed by '"' lines terminated by '\n';

以下是报道的内容:

Query OK, 1 row affected, 4 warnings (0.05 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 4

仅添加了 1 行,并且仅添加了部分?我究竟做错了什么?

我的表结构:

class Restaurant(models.Model):
name = models.CharField(max_length=200)
category = models.CharField(max_length=200)
city = models.CharField(max_length=200)
location= models.CharField(max_length=200)
address= models.CharField(max_length=500)
phone_number= models.IntegerField()
email= models.CharField(max_length=200)
description= models.CharField(max_length=2000)
hours= models.CharField(max_length=200)
photos= models.CharField(max_length=200)
price= models.CharField(max_length=200)
rating= models.IntegerField()
review= models.CharField(max_length=2000)

我的 csv 的前 4 行:

American Burger,American,Dhaka,,,,,,,,2 to 4,4
ARIRANG,Korean,Dhaka,,"House 3, Road 51, Gulshan 2, Dhaka, Bangladesh.",(88-02) 989-6453,,,,,,
Aroma,,Dhaka,,,,,,,,15 to 20,3.5
Bacaru,,Dhaka,,,,,,,,,4
4

2 回答 2

1

In your CSV file line separator is (0D 0A). So, you need to use '\r\n' as line separator -

...
lines terminated by '\r\n'
于 2013-01-29T13:32:04.687 回答
0

如果您的表有任何违反数据文件行的唯一约束,LOAD DATA INFILE则将跳过它们,如本文所示:

https://stackoverflow.com/a/20913896/445131

要么删除表上的所有唯一约束并重试,要么删除文本文件中每一行的每一列中的重复项并重试。

于 2014-01-03T22:45:41.203 回答