1

Here's the catch, it says at line 799569, but after opening the actual SQL file, and going to that line, the line is fine; and moreover, the database contains the data inserted at that line. The error must be somewhere else.

The error says nothing else than ERROR 1062 (23000) at line 799569: Duplicate entry '1' for key 'PRIMARY'. Not so informative.

How do I debug a Mysql import?

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • I think, you should truncate table before importing file. Or table structure is incorrect. For example you have PRINARY index but there is no increment – Alex Slipknot Mar 23 '17 at 14:21
  • Apparently one of the project's database migration files was inserting 1 row of data, so the import had a duplicate entry. – Christopher Francisco Mar 23 '17 at 15:08

1 Answers1

3

The message is actually quite informative. It means that the ID 1 you're trying to insert at row 799569 is already in the table, but since a primary key cannot have duplicate values you get that error.

You can solve that by using either INSERT IGNORE or INSERT ... ON DUPLICATE KEY UPDATE; the first one will skip the insert if the key already exists in the table, the other one will update the existing with the new values. You can read more about these two options here on SO or on MySQL documentation.

Community
  • 1
  • 1
Stefano Zanini
  • 5,876
  • 2
  • 13
  • 33
  • Why not link the mysql documentation rather – Rahul Mar 23 '17 at 14:24
  • You're right, the message is informative. The problem was that a database migration file was inserting a row. I had no way of knowing that since it passed the code review, so I had assumed the problem was something with the import script and an incorrect debug output. Thanks for the answer. – Christopher Francisco Mar 23 '17 at 15:10