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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현