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.

User not created when setting up Keystone with Postgres

See original GitHub issue

Bug report

I tried setting up Keybase following the getting started guide but on npm run dev it starts keystone but no user is created.

To Reproduce

Steps to reproduce the behaviour. Please provide code snippets or a repository:

  1. init Keystone
  2. install a Postgres database
  3. set the user confirguration for the postgres db
  4. start the server and see that no user is created

Expected behaviour

The user should be created immediately or there should be a screen that shows to create a user when starting the app like #1782.

Additional context

I tried to debug initial-data.js and changing following:

https://github.com/keystonejs/keystone/blob/06bff4119a44769b359006e8e6b9e07c32b21a8e/packages/create-keystone-app/example-projects/starter/initial-data.js#L6-L10

to:

  const res = await keystone.executeQuery(
    `query {
      _allUsersMeta {
        count
      }
    }`
  )
  console.log(res)
  // Count existing users
  const {
    data: {
      _allUsersMeta: { count },
    },
  } = res;

I got following error:

{
  errors: [
    error: relation "public.User" does not exist
        at Connection.parseE (./keystonejs/my-app/node_modules/pg/lib/connection.js:604:13)
        at Connection.parseMessage (./keystonejs/my-app/node_modules/pg/lib/connection.js:403:19)
        at Socket.<anonymous> (./keystonejs/my-app/node_modules/pg/lib/connection.js:123:22)
        at Socket.emit (events.js:210:5)
        at addChunk (_stream_readable.js:308:12)
        at readableAddChunk (_stream_readable.js:289:11)
        at Socket.Readable.push (_stream_readable.js:223:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
    From previous event:
        at Client_PG._query (./keystonejs/my-app/node_modules/knex/lib/dialects/postgres/index.js:236:12)
        at Client_PG.query (./keystonejs/my-app/node_modules/knex/lib/client.js:168:17)
        at Runner.query (./keystonejs/my-app/node_modules/knex/lib/runner.js:133:36)
        at ./keystonejs/my-app/node_modules/knex/lib/runner.js:39:23
        at ./keystonejs/my-app/node_modules/knex/lib/runner.js:253:24
        at processImmediate (internal/timers.js:439:21)
    From previous event:
        at Runner.ensureConnection (./keystonejs/my-app/node_modules/knex/lib/runner.js:251:8)
        at Runner.run (./keystonejs/my-app/node_modules/knex/lib/runner.js:25:12)
        at Builder.Target.then (./keystonejs/my-app/node_modules/knex/lib/interface.js:15:43) {
      message: 'select count(*) from "public"."User" as "t0" where true - relation "public.User" does not exist',
      locations: [Array],
      path: [Array]
    }
  ],
  data: [Object: null prototype] {
    _allUsersMeta: [Object: null prototype] { count: null }
  }
}

Not sure why.

System:

{
  "name": "@keystonejs/example-projects-starter",
  "description": "An example KeystoneJS project with a User list and Authentication.",
  "private": true,
  "version": "5.0.1",
  "author": "The KeystoneJS Development Team",
  "repository": "https://github.com/keystonejs/keystone.git",
  "homepage": "https://github.com/keystonejs/keystone",
  "license": "MIT",
  "engines": {
    "node": ">=8.4.0"
  },
  "scripts": {
    "dev": "cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev",
    "build": "cross-env NODE_ENV=production keystone build",
    "start": "cross-env NODE_ENV=production keystone start"
  },
  "dependencies": {
    "@keystonejs/adapter-knex": "^6.1.2",
    "@keystonejs/app-admin-ui": "^5.3.0",
    "@keystonejs/app-graphql": "^5.0.1",
    "@keystonejs/auth-password": "^5.0.1",
    "@keystonejs/fields": "^6.0.0",
    "@keystonejs/keystone": "^5.3.0",
    "cross-env": "^5.2.0"
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
MadeByMikecommented, Dec 20, 2019

Can you try setting the dropDatabase flag on the Adapter like this:

const keystone = new Keystone({
  name: PROJECT_NAME,
  adapter: new Adapter({dropDatabase:true}),
  onConnect: initialiseData,
});

That should force it to initialise

6reactions
dfintoncommented, Sep 17, 2020

@timfee - Yeah the docs need to be updated as they don’t really tell you what to do with a postgres database and the directions provided from command line are incorrect; they tell you to run npx keystone create-tables but that just spits out that error you got.

Instead of doing what the instructions tell you, you’ll need to run npm run create-tables or yarn create-tables. Then you can start up keystone in dev mode and it will create the admin@example.com user. The output of the command will tell you what the password is (it’s randomly generated).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keystone Next not showing database type and always select ...
Clone the Keystone repo and have a look at the examples directory. It's full of very simply starting points that use an SQLite...
Read more >
Authentication and Access Control - Keystone 6 Documentation
Learn how to use Keystone's built-in Authentication and Access Control systems.
Read more >
Configuring Keystone - OpenStack Docs
To configure the OpenStack services with service users, we need to create a project for all the services, and then users for each...
Read more >
Installing KeystoneJS 6, NodeJS, Yarn and PostgreSQL
This video walk you through 1. Installing NodeJS 2. Installing Yarn … Show more. Show more. Key moments. View all. What Is the...
Read more >
mmobj command - IBM
Use the mmobj command to modify and change the Object protocol service configuration, and to administer storage policies for Object Storage, unified file...
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