mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-108364: In sqlite3, disable foreign keys before dumping SQL schema (#113957)
sqlite3.Connection.iterdump now ensures that foreign key support is disabled before dumping the database schema, if there is any foreign key violation. Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
parent
fcb4c8d31a
commit
de777e490f
3 changed files with 18 additions and 3 deletions
|
@ -26,6 +26,10 @@ def _iterdump(connection):
|
|||
|
||||
writeable_schema = False
|
||||
cu = connection.cursor()
|
||||
# Disable foreign key constraints, if there is any foreign key violation.
|
||||
violations = cu.execute("PRAGMA foreign_key_check").fetchall()
|
||||
if violations:
|
||||
yield('PRAGMA foreign_keys=OFF;')
|
||||
yield('BEGIN TRANSACTION;')
|
||||
|
||||
# sqlite_master table contains the SQL CREATE statements for the database.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue