【问题标题】:How do I enable foreign key constraints for SQLite with Dropwizard and JDBI?如何使用 Dropwizard 和 JDBI 为 SQLite 启用外键约束?
【发布时间】:2017-09-06 23:01:35
【问题描述】:

我正在使用 Dropwizard 及其JDBI module 来连接到 SQLite 数据库。我已经设置了数据库,使其具有 FK,但我仍然需要告诉 SQLite 启用它的约束。

我知道你可以配置它using a properties instance,但我不知道如何将它与 Dropwizard 中的 JDBI 设置一起使用。

【问题讨论】:

    标签: java sqlite dropwizard jdbi


    【解决方案1】:

    您需要将以下属性添加到您的 .yml 设置文件中:foreign_keys: true

    它应该看起来像这样:

    database:
      # the name of your JDBC driver
      driverClass: org.sqlite.JDBC
    
      # the JDBC URL
      url: jdbc:sqlite:databasefile.db
    
      # any properties specific to your JDBC driver:
      properties:
        foreign_keys: true
    

    之后,您的 SQLite 数据库中应该有 FK 约束。您可以查看SQLiteConfig 类以了解更多属性。

    【讨论】:

      猜你喜欢
      • 2011-05-14
      • 2015-09-22
      • 2014-08-11
      • 1970-01-01
      • 2014-01-17
      • 2014-05-20
      • 2012-02-03
      • 2013-05-03
      相关资源
      最近更新 更多