-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Foreign key constraint just doesn't work #377
Comments
In fact, it seems that all Of course, for |
The documentation says:
With SQLite shell : sqlite> begin;
sqlite> PRAGMA foreign_keys = ON;
sqlite> create table foo (a);
sqlite> create table bar (a references foo(a));
sqlite> insert into bar values ('lol');
sqlite> commit;
sqlite> pragma foreign_key_check;
Error: foreign key mismatch - "bar" referencing "foo" |
I know. But you have to do This package used to allow opening files with |
Maybe a connection hook will do the job ? |
That's indeed what I eventually used. However, it would be nice for such a basic feature to be more easily accessible. The old |
Are you sure it was removed ? $ git log -p sqlite3.go | grep 'foreign_keys'
-- no match |
#255 (comment) That line no longer exists, and |
Sorry for the confusion. |
Perhaps it should be added and documented then? Having to use a connection hook to do things as basic as turning on foreign keys support is rather annoying. |
Well, I'm thinking it's possible to do with hook. But if many people want this feature, I'll add this. |
So now to enforce foreign key constrains, we can only do this: |
@maharasheed The connection parameter is db, err := sql.Open("sqlite3", "my.db?_foreign_keys=on") |
I have tried everything but still i am getting foreign key error . There are my two tables error: err:"near "fk_uploader_session": syntax error" |
@ManishaDutt01 Your syntax is invalid. See https://www.sqlite.org/lang_createtable.html It would be |
@rittneje Thanks understood |
I am probably misunderstanding something, but it appears that foreign key constraints are ignored no matter what I do. Here's an example:
Expected result: panic. Actual result:
test.db
gets created, with the values being inconsistent with the foreign key constraint.Why is this happening? I even recall using this package before with foreign keys without issue...
The text was updated successfully, but these errors were encountered: