Skip to content

Commit

Permalink
enable foreign keys in sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Nov 22, 2024
1 parent 2024132 commit 8ddb49b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion buildingmotif/database/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, List

from sqlalchemy import Column, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy import Column, ForeignKey, Integer, String, Text, UniqueConstraint, event
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Mapped, declarative_base, relationship

# from sqlalchemy.dialects.postgresql import JSON
Expand All @@ -9,6 +10,13 @@
Base = declarative_base()


# https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#foreign-key-support
@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()

class DBModel(Base):
"""A Model is a metadata model of all or part of a building."""

Expand Down

0 comments on commit 8ddb49b

Please sign in to comment.