在Clojure项目中使用Migratus与SQLite时找不到合适的驱动程序。

huangapple go评论80阅读模式
英文:

No suitable driver found when using Migratus with SQLite in a Clojure project

问题

I'm new to Clojure and I've been struggling to get Migratus to work with an SQLite database. I've been through a bit of debugging, and I feel stuck! 在Clojure项目中使用Migratus与SQLite时找不到合适的驱动程序。

The issue is that when I try running migrations, I get the following error:

Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:702).
No suitable driver found for jdbc:://127.0.0.1/

(which is weird: this should be referring to an SQLite file, not the local host)

Using java.sql.DriverManager, I can successfully establish a connection to the SQLite database manually. So, the driver seems to be set up correctly.

This is my project.clj:

(defproject sample-project "0.1.0-SNAPSHOT"
  :description "TODO"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [io.pedestal/pedestal.route "0.6.0"]
                 [io.pedestal/pedestal.service "0.6.0"]
                 [io.pedestal/pedestal.jetty "0.6.0"]
                 [org.clojure/java.jdbc "0.7.12"]
                 [org.xerial/sqlite-jdbc "3.42.0.0"]
                 [migratus/migratus "1.5.1"]
                 [buddy/buddy-hashers "2.0.167"]]
  :source-paths ["src"]
  :repl-options {:init-ns sample-project.core}
  :profiles {:dev {:aliases {"run-dev" ["trampoline" "run" "-m" "simple-api-proxy.werver/run-dev"]}
                   :dependencies [[io.pedestal/pedestal.service-tools "0.6.0"]}}}
  :main sample-project.core)

And this is how the run-migrations function is configured in core.clj:

(ns simple-api-proxy.db
  (:require [clojure.java.jdbc :as jdbc]
           [migratus.core :as migratus]))

(def db-spec 
 {:classname "org.sqlite.JDBC"
    :subprotocol "sqlite"
    :subname ":db.sqlite3"}) ; Also tried with 'db.sqlite3' and "jdbc:sqlite:db.sqlite3"

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn run-migrations "Run migrations" []
  (let [config {:store :database
                :migration-dir "resources/migrations"
                :db db-spec}]
    (migratus/migrate config)))

Am I missing something? Is there any incompatibility between Migratus and SQLite?

英文:

I'm new to Clojure and I've been struggling to get Migratus to work with an SQLite database. I've been through a bit of a debugging and I feel stuck! 在Clojure项目中使用Migratus与SQLite时找不到合适的驱动程序。

The issue is that, when I try running migrations, I get the following error:

Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:702).
No suitable driver found for jdbc:://127.0.0.1/

(which is weird: this should be referring to a SQLite file, not the local host)

Using java.sql.DriverManager, I can successfully establish a connection to the SQLite database manually. So the driver seems to be set up correctly.

This is my project.clj:

(defproject sample-project "0.1.0-SNAPSHOT"
  :description "TODO"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [io.pedestal/pedestal.route "0.6.0"]
                 [io.pedestal/pedestal.service "0.6.0"]
                 [io.pedestal/pedestal.jetty "0.6.0"]
                 [org.clojure/java.jdbc "0.7.12"]
                 [org.xerial/sqlite-jdbc "3.42.0.0"]
                 [migratus/migratus "1.5.1"]
                 [buddy/buddy-hashers "2.0.167"]]
  :source-paths ["src"]
  :repl-options {:init-ns sample-project.core}
  :profiles {:dev {:aliases {"run-dev" ["trampoline" "run" "-m" "simple-api-proxy.werver/run-dev"]}
                   :dependencies [[io.pedestal/pedestal.service-tools "0.6.0"]]}}
  :main sample-project.core)

And this is how the run-migrations function is configured in core.clj:

(ns simple-api-proxy.db
  (:require [clojure.java.jdbc :as jdbc]
           [migratus.core :as migratus]))

(def db-spec 
 {:classname "org.sqlite.JDBC"
    :subprotocol "sqlite"
    :subname ":db.sqlite3"}) ; Also tried with 'db.sqlite3' and "jdbc:sqlite:db.sqlite3"

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn run-migrations "Run migrations" []
  (let [config {:store :database
                :migration-dir "resources/migrations"
                :db db-spec}]
    (migratus/migrate config)))

Am I missing something? Is there any incompatibility between Migratus and SQLite?

答案1

得分: 1

afaik migratus 数据库规范声明使用不同的属性名称:

文档 中显示的内容如下:

:migratus {:store :database
           :migration-dir "migrations"
           :db {:dbtype "sqlite"
                :dbname "db.sqlite3"}}

因此,可能需要更新您的迁移规范。

英文:

afaik the migratus db spec declaration uses different prop names:

the documentation shows something like

:migratus {:store :database
           :migration-dir "migrations"
           :db {:dbtype "sqlite"
                :dbname "db.sqlite3"}}

so, probably you need to update your migration spec.

huangapple
  • 本文由 发表于 2023年7月24日 17:28:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定