简体   繁体   English

从csv导入MySQL时缺少int值

[英]Missing int values when importing from csv into MySQL

I'm currently building a database that works with helping students build a class schedule. 我目前正在建立一个数据库,可以帮助学生建立课程表。 I've "succeeded" in importing two of the three columns using a csv file but I'm having issues importing the ID numbers for the fields the classes are apart of. 我已经成功地使用csv文件导入了三列中的两列,但是导入类所属的字段的ID号时遇到了问题。 I think it has something to do with the ID being a int file, since the other two columns are varchar's. 我认为这与ID是一个i​​nt文件有关,因为其他两列是varchar。 But having the column be int makes the rest of my project incredibly easy... 但是将列设为int使我的项目其余部分变得异常容易...

A small portion of the csv file reads: csv文件的一小部分内容如下:

1,AFAM,2000
1,AFAM,3150
1,PSYC,3150
1,AFAM,3880
1,AFAM,4200
2,POLS,4200
2,AFAM,4490
2,AFAM,6490
2,DRAM,4490
2,DRAM,6490
2,AFAM,4500

Then I use this in MySQL: 然后我在MySQL中使用它:

LOAD DATA local INFILE 'Course_Requirements.csv' INTO TABLE Courses
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';

When I go SELECT * FROM COURSES; 当我SELECT * FROM COURSES; to view my table it shows up like this: 查看我的表,它显示如下:

ID  |  ClassName  |  ClassNumber
    |  AFAM       |  2000
    |  AFAM       |  3150
    |  PSYC       |  3150
    |  AFAM       |  3880
    |  AFAM       |  4200
    |  POLS       |  4200
    |  AFAM       |  4490
    |  AFAM       |  6490
    |  DRAM       |  4490
    |  DRAM       |  6490
 2  |  AFAM       |  4500

I honestly have no idea why the IDs aren't showing up... 老实说,我不知道为什么没有显示ID ...

Make sure the ID column in Courses is not primary key or unique. 确保“课程”中的“ ID”列不是主键或唯一。 If not you cannot have duplicates. 如果没有,则不能重复。 execute: 执行:

SHOW CREATE TABLE Courses

and look at the properties of the ID column 并查看ID列的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM