How to enable foreign key validation in SQLite with Slickplay framework - SQLite: Enable Foreign KeyHow to list the tables in a SQLite database file that was opened with ATTACH?Sqlite primary key on multiple columnsHow do I check in SQLite whether a table exists?Enabling Foreign key constraints in SQLiteDoes SQLite coupled with NHibernate support referential integrity / foreign keys?How do you enforce foreign key constraints in SQLite through Java?How to turn on foreign keys in FMDatabase?How to use correctly foreign keys in Android, using SQLite and OrmLiteEnable foreign key support for Sqlite3 in CakePHPForeign Key constraint failed - SQLite with Entity Framework
Defense against attacks using dictionaries
Why different interest rates for checking and savings?
How would one country purchase another?
What magic extends life or grants immortality?
Is it possible to get crispy, crunchy carrots from canned carrots?
In the MCU, why does Mjölnir retain its enchantments after Ragnarok?
Fried gnocchi with spinach, bacon, cream sauce in a single pan
Is using a hyperlink to close a modal a poor design decision?
What to say to a student who has failed?
How to prevent cutting edges on my TV, HDMI-connected?
how do you harvest carrots in creative mode
See details of old sessions
Does travel insurance for short flight delays exist?
Sun setting in East!
for loop not working in bash
Most practical knots for hitching a line to an object while keeping the bitter end as tight as possible, without sag?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
Why is my Earth simulation slower than the reality?
Why do all fields in a QFT transform like *irreducible* representations of some group?
Attaching a piece of wood to a necklace without drilling
Is it safe to remove the bottom chords of a series of garage roof trusses?
In an emergency, how do I find and share my position?
C++20 constexpr std::copy optimizations for run-time
Who was president?
How to enable foreign key validation in SQLite with Slick
play framework - SQLite: Enable Foreign KeyHow to list the tables in a SQLite database file that was opened with ATTACH?Sqlite primary key on multiple columnsHow do I check in SQLite whether a table exists?Enabling Foreign key constraints in SQLiteDoes SQLite coupled with NHibernate support referential integrity / foreign keys?How do you enforce foreign key constraints in SQLite through Java?How to turn on foreign keys in FMDatabase?How to use correctly foreign keys in Android, using SQLite and OrmLiteEnable foreign key support for Sqlite3 in CakePHPForeign Key constraint failed - SQLite with Entity Framework
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to enable foreign key validation in SQLite through Slick. I'm using Slick 3.3.0. How do I do this?
Currently I'm connecting to SQLite through a DatabaseConfig[SQLiteProfile]
, by doing
DatabaseConfig.forConfig(path = configKey, classLoader = getClass.getClassLoader)
My config looks like this:
"dataSourceClass": "slick.jdbc.DatabaseUrlDataSource",
"db":
"driver": "org.sqlite.JDBC",
"properties":
"foreign_keys": true
,
"url": "jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on"
,
"profile": "slick.jdbc.SQLiteProfile$"
I've tried adding ?foreign_keys=ON
to the end of my JDBC URL. I've also tried moving the properties
object out of the db
object and into the root level.
If I interact with the database directly through JDBC I'm able to get it work:
package test
import java.sql.DriverManager
object Main extends App
val connection = DriverManager.getConnection(
"jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on")
val statement = connection.createStatement()
// this line throws, because table_with_fk is a table
// with foreign keys into a different table
statement.executeUpdate(
"insert into table_with_fk values (0, 0, 0, 0, 0, 0, 0, 0)")
scala sqlite slick
add a comment |
I want to enable foreign key validation in SQLite through Slick. I'm using Slick 3.3.0. How do I do this?
Currently I'm connecting to SQLite through a DatabaseConfig[SQLiteProfile]
, by doing
DatabaseConfig.forConfig(path = configKey, classLoader = getClass.getClassLoader)
My config looks like this:
"dataSourceClass": "slick.jdbc.DatabaseUrlDataSource",
"db":
"driver": "org.sqlite.JDBC",
"properties":
"foreign_keys": true
,
"url": "jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on"
,
"profile": "slick.jdbc.SQLiteProfile$"
I've tried adding ?foreign_keys=ON
to the end of my JDBC URL. I've also tried moving the properties
object out of the db
object and into the root level.
If I interact with the database directly through JDBC I'm able to get it work:
package test
import java.sql.DriverManager
object Main extends App
val connection = DriverManager.getConnection(
"jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on")
val statement = connection.createStatement()
// this line throws, because table_with_fk is a table
// with foreign keys into a different table
statement.executeUpdate(
"insert into table_with_fk values (0, 0, 0, 0, 0, 0, 0, 0)")
scala sqlite slick
add a comment |
I want to enable foreign key validation in SQLite through Slick. I'm using Slick 3.3.0. How do I do this?
Currently I'm connecting to SQLite through a DatabaseConfig[SQLiteProfile]
, by doing
DatabaseConfig.forConfig(path = configKey, classLoader = getClass.getClassLoader)
My config looks like this:
"dataSourceClass": "slick.jdbc.DatabaseUrlDataSource",
"db":
"driver": "org.sqlite.JDBC",
"properties":
"foreign_keys": true
,
"url": "jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on"
,
"profile": "slick.jdbc.SQLiteProfile$"
I've tried adding ?foreign_keys=ON
to the end of my JDBC URL. I've also tried moving the properties
object out of the db
object and into the root level.
If I interact with the database directly through JDBC I'm able to get it work:
package test
import java.sql.DriverManager
object Main extends App
val connection = DriverManager.getConnection(
"jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on")
val statement = connection.createStatement()
// this line throws, because table_with_fk is a table
// with foreign keys into a different table
statement.executeUpdate(
"insert into table_with_fk values (0, 0, 0, 0, 0, 0, 0, 0)")
scala sqlite slick
I want to enable foreign key validation in SQLite through Slick. I'm using Slick 3.3.0. How do I do this?
Currently I'm connecting to SQLite through a DatabaseConfig[SQLiteProfile]
, by doing
DatabaseConfig.forConfig(path = configKey, classLoader = getClass.getClassLoader)
My config looks like this:
"dataSourceClass": "slick.jdbc.DatabaseUrlDataSource",
"db":
"driver": "org.sqlite.JDBC",
"properties":
"foreign_keys": true
,
"url": "jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on"
,
"profile": "slick.jdbc.SQLiteProfile$"
I've tried adding ?foreign_keys=ON
to the end of my JDBC URL. I've also tried moving the properties
object out of the db
object and into the root level.
If I interact with the database directly through JDBC I'm able to get it work:
package test
import java.sql.DriverManager
object Main extends App
val connection = DriverManager.getConnection(
"jdbc:sqlite:/path/to/mydb.sqlite?foreign_keys=on")
val statement = connection.createStatement()
// this line throws, because table_with_fk is a table
// with foreign keys into a different table
statement.executeUpdate(
"insert into table_with_fk values (0, 0, 0, 0, 0, 0, 0, 0)")
scala sqlite slick
scala sqlite slick
edited Mar 27 at 16:42
torkel
asked Mar 27 at 16:37
torkeltorkel
1076 bronze badges
1076 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
According to play framework - SQLite: Enable Foreign Key, SQLite requires you to enable this at the connection level. And that is consistent with your example (you are passing the foreign key option to getConnection
)
If you're using connection pooling behind the scenes, maybe that's why it doesn't work. Try disabling like in the database config example.
Alternatively try running a plain SQL statement with the pragma command PRAGMA foreign_keys = ON
before running your query.
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is aDBIOAction
, which is a monad. You can try chaining together operations usingflatMap
e.g. in afor
comprehension, or the>>
opeator, which throws away the result of the first value.
– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382319%2fhow-to-enable-foreign-key-validation-in-sqlite-with-slick%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to play framework - SQLite: Enable Foreign Key, SQLite requires you to enable this at the connection level. And that is consistent with your example (you are passing the foreign key option to getConnection
)
If you're using connection pooling behind the scenes, maybe that's why it doesn't work. Try disabling like in the database config example.
Alternatively try running a plain SQL statement with the pragma command PRAGMA foreign_keys = ON
before running your query.
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is aDBIOAction
, which is a monad. You can try chaining together operations usingflatMap
e.g. in afor
comprehension, or the>>
opeator, which throws away the result of the first value.
– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
add a comment |
According to play framework - SQLite: Enable Foreign Key, SQLite requires you to enable this at the connection level. And that is consistent with your example (you are passing the foreign key option to getConnection
)
If you're using connection pooling behind the scenes, maybe that's why it doesn't work. Try disabling like in the database config example.
Alternatively try running a plain SQL statement with the pragma command PRAGMA foreign_keys = ON
before running your query.
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is aDBIOAction
, which is a monad. You can try chaining together operations usingflatMap
e.g. in afor
comprehension, or the>>
opeator, which throws away the result of the first value.
– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
add a comment |
According to play framework - SQLite: Enable Foreign Key, SQLite requires you to enable this at the connection level. And that is consistent with your example (you are passing the foreign key option to getConnection
)
If you're using connection pooling behind the scenes, maybe that's why it doesn't work. Try disabling like in the database config example.
Alternatively try running a plain SQL statement with the pragma command PRAGMA foreign_keys = ON
before running your query.
According to play framework - SQLite: Enable Foreign Key, SQLite requires you to enable this at the connection level. And that is consistent with your example (you are passing the foreign key option to getConnection
)
If you're using connection pooling behind the scenes, maybe that's why it doesn't work. Try disabling like in the database config example.
Alternatively try running a plain SQL statement with the pragma command PRAGMA foreign_keys = ON
before running your query.
answered Apr 2 at 16:17
LucianoLuciano
1,47612 silver badges27 bronze badges
1,47612 silver badges27 bronze badges
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is aDBIOAction
, which is a monad. You can try chaining together operations usingflatMap
e.g. in afor
comprehension, or the>>
opeator, which throws away the result of the first value.
– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
add a comment |
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is aDBIOAction
, which is a monad. You can try chaining together operations usingflatMap
e.g. in afor
comprehension, or the>>
opeator, which throws away the result of the first value.
– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
The last code snippet is not what I've tried in my application, its something I made to show what I did get to work, although not in a way that satisfies my need. Do you know how I combine a plain SQL statement with a compiled Slick query? I've tried, but can't figure it out.
– torkel
Apr 2 at 16:41
@torkel the result of both operations is a
DBIOAction
, which is a monad. You can try chaining together operations using flatMap
e.g. in a for
comprehension, or the >>
opeator, which throws away the result of the first value.– Luciano
Apr 2 at 17:20
@torkel the result of both operations is a
DBIOAction
, which is a monad. You can try chaining together operations using flatMap
e.g. in a for
comprehension, or the >>
opeator, which throws away the result of the first value.– Luciano
Apr 2 at 17:20
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
After fiddling a bit it turned out I wasn't able to compose the query because of a too strict type annotation I had. Your suggestion worked! Thank you.
– torkel
Apr 4 at 8:27
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382319%2fhow-to-enable-foreign-key-validation-in-sqlite-with-slick%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown