简体   繁体   中英

Relation "schema.table" does not exist exception thrown when using slick 3.3.3

Problem: So I am trying to connect to a PostgreSql DB with scala slick v3.3.3 and it is failing to find the relation (table) users in schema 'one' within the 'onetest' Database.

I have the following Table setup:

CREATE SCHEMA one;
CREATE TABLE one.users (
...
);

and the table definition:

class UsersTable(tag: Tag) extends Table[UserRequest](tag, Some("one"), "users") {
...
}

with database configuration:

onedbtest = {
  profile = "slick.jdbc.PostgresProfile$"
  db = {
    dataSourceClass = "org.postgresql.ds.PGSimpleDataSource" //Simple datasource with no connection pooling. The connection pool has already been specified with HikariCP.
    driver = "slick.driver.PostgresDriver$"
    serverName = "localhost"
    portNumber = "5432"
    databaseName = "onetest"
    user = onetestuser
    password = "password"
    connectionPool = disabled
  }
}

and when running (with necessary imports): dbConfig.db.run((usersTable += createUserRequest).asTry)

Why can it not find relations (tables) in db?

Note: Error does not appear (with tests passing) when: keepAliveConnection = true is added to config for DB initialisation however, it writes to another db called "one" (dev environment) doesn't work when connectionPool = disabled is added. It should work with the connectionPool attribute added but it doesn't. Strange it is referencing another DB when the db isn't defined anywhere within the code. I am using sbt.version = 1.3.13 and scalaVersion := "2.12.6". sbt clean compile and rebuilding does not solve caching issues. I have also killed all processes to stop any open connections and used db.close where necessary.

I swapped dataSourceClass = "org.postgresql.ds.PGSimpleDataSource" with dataSourceClass = "slick.jdbc.DatabaseUrlDataSource" . This enables the application to actually close collections and not just return connection to connection pool. This in turn allows the application to initialise a new connection to the relevant db and pick up any modifications to the db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM