SQLite reflection doesn't detect DEFERRABLE and INITIALLY options on foreign keys
See original GitHub issueDescribe the bug
SQLite supports foreign keys with the DEFERRABLE
and INITIALLY
options. Reflection doesn’t detect these however, which causes bogus Alembic changes if these are used.
To Reproduce
from sqlalchemy import create_engine, inspect
conn = create_engine("sqlite:///:memory:").connect()
conn.exec_driver_sql("CREATE TABLE test1 (id INTEGER)")
conn.exec_driver_sql("CREATE TABLE test2 (ref INTEGER, CONSTRAINT ref FOREIGN KEY(ref) REFERENCES test1(id) DEFERRABLE INITIALLY DEFERRED)")
print(inspect(conn).get_foreign_keys("test2"))
Error
[{'name': 'ref', 'constrained_columns': ['ref'], 'referred_schema': None, 'referred_table': 'test1', 'referred_columns': ['id'], 'options': {}}]
options
is empty.
Versions
- OS: Linux
- Python: 3.10
- SQLAlchemy: 1.4.44
- Database: SQLite
- DBAPI (eg: psycopg, cx_oracle, mysqlclient): pysqlite
Additional context
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SQLite Foreign Key Support
This document describes the support for SQL foreign key constraints introduced in SQLite version 3.6.19 (2009-10-14). The first section ...
Read more >Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed
If you have ForeignKey constraints they are now enforced at the database level. So make sure you're not violating a foreign key constraint....
Read more >Defining Constraints and Indexes
Defining Foreign Keys. A foreign key in SQL is a table-level construct that constrains one or more columns in that table to only...
Read more >1.4.x Milestone - GitHub
SQLite reflection doesn't detect DEFERRABLE and INITIALLY options on foreign keys next release addition to the milestone which indicates this should be in ......
Read more >SQLite Foreign Key: Enforce Relationships Between Tables
If the SQLite library is compiled with foreign key constraint support, the application can use the PRAGMA foreign_keys command to enable or disable...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This looks short (that was fast too thanks) I can just cherry-pick it just as easily, thanks
#8904 for main. Should I make a separate PR for 1.4?