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;








2















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)")










share|improve this question
































    2















    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)")










    share|improve this question




























      2












      2








      2








      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)")










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 16:42







      torkel

















      asked Mar 27 at 16:37









      torkeltorkel

      1076 bronze badges




      1076 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2







          +100








          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.






          share|improve this answer

























          • 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











          • 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










          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
          );



          );













          draft saved

          draft discarded


















          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









          2







          +100








          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.






          share|improve this answer

























          • 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











          • 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















          2







          +100








          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.






          share|improve this answer

























          • 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











          • 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













          2







          +100







          2







          +100



          2






          +100





          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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

















          • 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











          • 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








          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.



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript