Mysterious foreign-key error #121
-
At the moment, the package I'm developing uses a single database and the table definitions are as follows. (mapcar (lambda (expression)
(emacsql (w-project-database-connection project) expression))
;; A list of SQL s-expressions to create the tables.
'([:create-table-if-not-exists module
([module-name content file-name section-name displacement
module-number]
(:primary-key [module-number module-name file-name]))]
;; FIXME: EmacSQL had an unhandled condition: "foreign key
;; mismatch - \"parent_child\" referencing \"module\"", 1,
;; nil, "SQL logic error"
[:create-table-if-not-exists parent-child
([(parent integer) (child integer)]
(:primary-key [parent child])
(:foreign-key [parent] :references module [module-number]
:on-delete :cascade)
(:foreign-key [child] :references module [module-number]
:on-delete :cascade))]
[:create-table-if-not-exists identifier-used-in-module
([identifier-name
(module-number integer)
(line-number integer)
type-of-usage]
(:primary-key [identifier-name module-number line-number
type-of-usage]))]
[:create-table-if-not-exists topic-referenced-in-module
([topic-name (module-number integer)]
(:primary-key [topic-name module-number]))])) This results in the following error: Any help or guidance would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I just read over the specification again. It's because I said that |
Beta Was this translation helpful? Give feedback.
I don't know and would have to experiment to find out, for which I don't have the time now.
I think the information at https://github.com/magit/emacsql?tab=readme-ov-file#schema is incorrect. As mentioned there and elsewhere in the documentation, everything is stored as strings (except
nil
for whichnull
is used).integer
andfloat
are therefore not valid. I don't know whatobject
is; if it is not the same as "string", then that would also be invalid.