peewee.IntegrityError

I get an error when I try to use the drop command. I’m using mysql and the user in question have all privileges to the specific database.

The error message I get is this:

peewee.IntegrityError: (1451, ‘Cannot delete or update a parent row: a foreign key constraint fails (google_dni_folketinget_prodigy.link, CONSTRAINT link_ibfk_2 FOREIGN KEY (dataset_id) REFERENCES dataset (id))’)

What can I do to fix this?

I’m seeing the same error as well. Here’s the command I used:

prodigy drop raw_dataset

and the stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
  File "/usr/local/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute
    result = self._query(query)
  File "/usr/local/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result
    result.read()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet
    packet.check_error()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`prodigy`.`link`, CONSTRAINT `link_ibfk_2` FOREIGN KEY (`dataset_id`) REFERENCES `dataset` (`id`))')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/site-packages/prodigy/__main__.py", line 246, in <module>
    plac.call(commands[command], arglist=args, eager=False)
  File "/usr/local/lib/python3.6/site-packages/plac_core.py", line 328, in call
    cmd, result = parser.consume(arglist)
  File "/usr/local/lib/python3.6/site-packages/plac_core.py", line 207, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "/usr/local/lib/python3.6/site-packages/prodigy/__main__.py", line 143, in drop
    dropped = DB.drop_dataset(set_id)
  File "cython_src/prodigy/components/db.pyx", line 304, in prodigy.components.db.Database.drop_dataset
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 3614, in execute
    return self.database.rows_affected(self._execute())
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2939, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 3837, in execute_sql
    self.commit()
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 3656, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 135, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/site-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
  File "/usr/local/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute
    result = self._query(query)
  File "/usr/local/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result
    result.read()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet
    packet.check_error()
  File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
peewee.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`prodigy`.`link`, CONSTRAINT `link_ibfk_2` FOREIGN KEY (`dataset_id`) REFERENCES `dataset` (`id`))')

likewise I get the same error when I try and drop a database. using MySQL!

We’re going to push a patch release today that addresses other bugs, but we haven’t been able to resolve this issue. As a mitigation, we’ll include the prodigy.db source in the release. This should make the problem much easier to debug, so that we can get this fixed as quickly as possible. You’ll also be able to modify the file if you see a quick workaround for the problem.

Just released v1.4.2 which includes a fix for this issue – I hope it all works now :crossed_fingers: Thanks to @justindujardin for the help on this!

2 Likes

I had to remove the old compiled cpython files from site-packages/prodigy/components/ to get the v1.4.2 build to work with MySQL and prodigy drop [dataset]:

48 PM

It works as expected for me now, thanks!

@justindujardin Ah, thanks!

We just updated the v1.4.2 wheels with new versions that definitely don’t include any leftover cpython files. (If you still come across them, they might be artifacts from a previous installation – so you can either delete them manually or do a clean install in a fresh environment.)