keystonejs / keystone

The superpowered headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
9.18k stars 1.15k forks source link

Adding new list causes "GraphQL error: select count(*)" error #3024

Closed andregoldstein closed 4 years ago

andregoldstein commented 4 years ago

When creating first list on fresh install, receive GraphQL error in admin dashboard

When trying to add my first list on a fresh install using Postgres and the users/auth starter I receive a GraphQL error when logging into admin

GraphQL error: select count(*) from "public"."Clinic" as "t0" where true - relation "public.Clinic" does not exist
GraphQL error: select "t0".* from "public"."Clinic" as "t0" where true order by "name" ASC limit $1 - relation "public.Clinic" does not exist GraphQL error: select count(*) from "public"."Clinic" as "t0" where true and "t0"."name" ~* $1 - relation "public.Clinic" does not exist

To Reproduce

  1. Install with yarn create keystone-app app-name
  2. Choose users/auth starter
  3. Choose Postgres and postgres connection string (connects ok)
  4. Run yarn create-tables
  5. Add the following code to add a Clinic list:
keystone.createList('Clinic', {
  fields: {
    name: { type: Text },
  },
  // List-level access controls
  access: {
    read: access.userIsAdminOrOwner,
    update: access.userIsAdminOrOwner,
    create: access.userIsAdmin,
    delete: access.userIsAdmin,
    auth: true,
  },
})

Expected behaviour

Expected to be able to access this new model in the admin

System information

MadeByMike commented 4 years ago

It's likely you need to run yarn create-tables. For the Knex Adapter Keystone will not automatically initialise an SQL database, but there is a command to do this.

You can see the docs on initialising tables here: https://www.keystonejs.com/quick-start/#installing-keystone

molomby commented 4 years ago

Clarifying @MadeByMike's comment -- the yarn create-tables command creates tables in your DB for the lists currently defined in your Keystone schema. Based on your reproduction steps, it looks like you may have run yarn create-tables (step 4) then added the list to your schema (step 5). Just reverse these two steps!

andregoldstein commented 4 years ago

Hi @molomby thanks so much for your reply, I will go back to my project and try it this way around, it's possible I hadn't got it the right way around!