This looks like MDL-51694. As far as I can tell the problem that leads to this error has been fixed but for sites that already have this problem there's currently no fix.
I've added a comment to the Tracker issue asking for more information. You can run the SELECT statement to see if there any rows are returned:
select * from mdl_grade_grades where itemid not in (select id from mdl_grade_items)
If rows are returned – if there was no problem then there shouldn't be – there's a suggested DELETE statement to tidy those up, ensure you have a database backup before making any changes to the database:
DELETE from mdl_grade_grades where itemid not in (select id from mdl_grade_items)