Closed kamakazikamikaze closed 4 months ago
For the SQLite error, that's because the pyDAL dialect doesn't support the statement (not sure if it's just pyDAL or SQLite itself that doesn't support that kind of constraint).
For the postgreSQL one, as of today there's no support in Emmett ORM to define reference columns as primary keys.
You will waste a column in Activity
, but removing the primary_keys
definition and adding an unique index on badge
will ensure 1:1 relationship.
Understood. Had to add "unique": True
when setting the index and now everything is working as designed. Appreciate it!
Using Emmett v2.5.13
The Issue
I have two tables defined as follows:
Their definition is intended to enforce a 1:1 relationship so that an
Activity
entry cannot exist without first registering aBadge
entry. I have noticed two different behaviors depending on the database used as the backend, however they both appear to be caused from Foreign Key definitions.SQLite
When attempting to generate a migration or launch via
emmett develop
, aKeyError
is immediately raised:Postgres
When Postgres is defined as the back-end, no errors are raised with migrations. In fact, I can create a
Badge
entry and then attempt to create an associatedActivity
entry but this gets raised:I can wrap this with a
try-except
statement and perform adb.commit()
action anyways with the results being correctly recorded to the database. However, triggers (after_insert
andafter_update
) do not seem to kick off, likely due to the exception.Additional notes
Badge
to a single primary key, this issue is not raised.