On this page
sqlite3.IntegrityError
Prev: sqlite3.Error | Up: sqlite3 | Next: sqlite3.InterfaceError
Rel: sqlite3.adapt, sqlite3.Binary, sqlite3.Blob, sqlite3.complete_statement
Ref: docs.python.org โ sqlite3.IntegrityError
Tags: #public #python3 #stdlib #sqlite3
Import
import sqlite3
from sqlite3 import IntegrityError
Signature & Overview
sqlite3.IntegrityError(...)
sqlite3.IntegrityError class.
Methods & Attributes
IntegrityError.add_note(self, note, /)โ Add a note to the exceptionIntegrityError.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE users (id INTEGER PRIMARY KEY)")
con.execute("INSERT INTO users VALUES (1)")
try:
con.execute("INSERT INTO users VALUES (1)")
except sqlite3.IntegrityError as exc:
assert "UNIQUE" in str(exc)
finally:
con.close()
Gotchas
- Raised on
UNIQUE,PRIMARY KEY,NOT NULL,CHECK, orFOREIGN KEYviolations: Remember that foreign keys are OFF in SQLite until you runPRAGMA foreign_keys = ON.
REPL Inspect
from sqlite3 import IntegrityError
help(IntegrityError)
Linked from
Related notes
- tuts/python3/stdlib_module/sqlite3 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Error Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/InterfaceError Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/adapt Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Binary Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Blob Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/complete_statement Linked here; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib