question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration CLI error: no schema has been selected to create in

See original GitHub issue

Knex: 0.12.6 PostgreSQL 9.6.1 on x86_64-pc-linux-gnu, compiled by gcc (Alpine 6.2.1) 6.2.1 20160822, 64-bit Node: 7.5.0 OS: Windows 10

Is it possibly because I dropped the public schema and replaced it with another one - database_schema. How do I interact with the migration CLI and the database?

**// knexfile.js**
module.exports = {
  development: {
    client: 'postgresql',
    connection: {
      database: 'database_development',
      user:     'admin_user',
      password: 'admin_password',
      host: '192.168.99.100'
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  }
};

This might be me misunderstanding Knex (first time using it), but I’m running into this problem:

λ knex migrate:currentVersion
Using environment: development
error: no schema has been selected to create in
    at Connection.parseE (C:\Users\Toby\git\min-auth\min-auth-server\node_modules\pg\lib\connection.js:554:11)
    at Connection.parseMessage (C:\Users\Toby\git\min-auth\min-auth-server\node_modules\pg\lib\connection.js:381:17)
    at Socket.<anonymous> (C:\Users\Toby\git\min-auth\min-auth-server\node_modules\pg\lib\connection.js:117:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:189:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)

Connecting with PSQL works with the same arguments, as does connection with Knex outside the migration CLI.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
imduchycommented, Mar 30, 2020

I’m experiencing the same issue and setting searchPath in the knexfile doesn’t help.

const knexConfig = (module.exports = {
    test: {
	client: 'pg',
	connection: {
	    host: 'localhost',
            port: 5432,
       	    user: 'myadmin',
	    password: process.env.POSTGRES_PASSWORD,
	    database: 'mydatabase-test',
	},
	searchPath: ['myadmin', 'myschema'],
	migrations: {
            directory: __dirname + '/db/migrations',
            extension: 'ts',
	},
	seeds: {
            directory: __dirname + '/db/seeds',
	},
    },
$ knex migrate:latest --env test
Requiring external module ts-node/register
Using environment: test
error: create table "knex_migrations" ("id" serial primary key, "name" varchar(255), "batch" integer, "migration_time" timestamptz) - no schema has been selected to create in

// EDIT:

Alright, I had to explicitly specify schemaName field within a migrations object. This solved the problem.

migrations: {
    directory: __dirname + '/db/migrations',
    extension: 'ts',
    schemaName: 'myschema'
},
3reactions
elhigucommented, Feb 4, 2017

Does this work (added searchPath configuration)

**// knexfile.js**
module.exports = {
  development: {
    client: 'postgresql',
    searchPath: 'database_schema',
    connection: {
      database: 'database_development',
      user:     'admin_user',
      password: 'admin_password',
      host: '192.168.99.100'
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR: no schema has been selected to create in
I am working on an amazon RDS postgresql database where I know there had been some issue with the public schema ( ...
Read more >
python - No schema has been selected to create in ... error
no schema has been selected to create in. You get this error when your search_path setting has no valid first entry (typically empty)....
Read more >
ERROR: no schema has been selected to create in #9528
I have the same error running npx prisma migrate dev --name initial-migration --create-only in a newly created database. datasource db { ...
Read more >
no schema has been selected to create in - SonarQube
PSQLException : ERROR: no schema has been selected to create in Position: 14 at org.postgresql.core.v3.QueryExecutorImpl.
Read more >
SQLSTATE[3F000]: Invalid schema name - Laracasts
[Illuminate\Database\QueryException] SQLSTATE[3F000]: Invalid schema name: 7 ERROR: no schema has been selected to create in (SQL: create table "migrations" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found