# peewee.IntegrityError

**URL:** <https://support.prodi.gy/t/peewee-integrityerror/443>\
**Category:** Uncategorized\
**Tags:** done, database\
**Created:** [March 27, 2018, 8:42am UTC](https://support.prodi.gy/t/peewee-integrityerror/443 "2018-03-27T08:42:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronnie](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ronnie/32/203_2.png) [@ronnie](https://support.prodi.gy/u/ronnie)\
**Post date:** [March 27, 2018, 8:42am UTC](https://support.prodi.gy/t/peewee-integrityerror/443/1 "2018-03-27T08:42:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![beckerfuffle](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/beckerfuffle/32/159_2.png) [@beckerfuffle](https://support.prodi.gy/u/beckerfuffle)\
**Post date:** [March 27, 2018, 7:02pm UTC](https://support.prodi.gy/t/peewee-integrityerror/443/2 "2018-03-27T19:02:49Z")

</div>

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

```bash
prodigy drop raw_dataset

```

and the stack trace:

```python
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`))')

```

---

<div class="post-metadata">

**Author:** ![deltahedge1](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@deltahedge1](https://support.prodi.gy/u/deltahedge1)\
**Post date:** [April 10, 2018, 5:15am UTC](https://support.prodi.gy/t/peewee-integrityerror/443/3 "2018-04-10T05:15:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![honnibal](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/honnibal/32/35_2.png) [@honnibal](https://support.prodi.gy/u/honnibal)\
**Post date:** [April 10, 2018, 12:45pm UTC](https://support.prodi.gy/t/peewee-integrityerror/443/4 "2018-04-10T12:45:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [April 10, 2018, 8:28pm UTC](https://support.prodi.gy/t/peewee-integrityerror/443/5 "2018-04-10T20:28:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![justindujardin](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/justindujardin/32/169_2.png) [@justindujardin](https://support.prodi.gy/u/justindujardin)\
**Post date:** [April 10, 2018, 8:37pm UTC](https://support.prodi.gy/t/peewee-integrityerror/443/6 "2018-04-10T20:37:04Z")

</div>

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](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/1X/7297048d67279ac18b5b4088e7a9dd12268c197c.png)

It works as expected for me now, thanks!

---

<div class="post-metadata">

**Author:** ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)\
**Post date:** [April 10, 2018, 9:25pm UTC](https://support.prodi.gy/t/peewee-integrityerror/443/7 "2018-04-10T21:25:21Z")

</div>

@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.)
