docker icon indicating copy to clipboard operation
docker copied to clipboard

Creating first user in Prisma studio "The column `Availability.label` does not exist in the current database."

Open drwb opened this issue 2 years ago • 20 comments

In step 8 of the readme.md instructions, notwithstanding the workaround for #121, Prisma studio throws the following error when trying to save the fist user:

Type: PrismaClientKnownRequestError
Message: 
Invalid `prisma.user.create()` invocation:


  The column `Availability.label` does not exist in the current database.

Code: P2022

Query:
prisma.user.create(
{
  data: {
    username: "drwb",
    name: "Name",
    email: "[email protected]",
    emailVerified: "2022-05-22T00:00:00.000Z",
    password: "bcrypthash",
    bio: null,
    avatar: null,
    timeZone: "Region/City",
    weekStart: "Sunday",
    startTime: 0,
    endTime: 1440,
    bufferTime: 0,
    hideBranding: true,
    theme: null,
    createdDate: "2022-05-22T00:00:00.000Z",
    eventTypes: {

    },
    credentials: {

    },
    teams: {

    },
    bookings: {

    },
    availability: {

    },
    selectedCalendars: {

    },
    completedOnboarding: false,
    locale: null,
    twoFactorSecret: null,
    twoFactorEnabled: false,
    plan: "PRO",
    Schedule: {

    },
    webhooks: {

    },
  },
  select: {
    id: true,
    username: true,
    name: true,
    email: true,
    emailVerified: true,
    password: true,
    bio: true,
    avatar: true,
    timeZone: true,
    weekStart: true,
    startTime: true,
    endTime: true,
    bufferTime: true,
    hideBranding: true,
    theme: true,
    createdDate: true,
    eventTypes: true,
    credentials: true,
    teams: true,
    bookings: true,
    availability: true,
    selectedCalendars: true,
    completedOnboarding: true,
    locale: true,
    twoFactorSecret: true,
    twoFactorEnabled: true,
    plan: true,
    Schedule: true,
    webhooks: true,
  },
}
)

When browsing the availability field, it throws the error:

Message: Error in Prisma Client request: 
Invalid `prisma.availability.findMany()` invocation:
  The column `Availability.label` does not exist in the current database.
Query:
prisma.availability.findMany({
  where: {
    AND: [
    ]
  },
  take: 100,
  skip: 0,
  select: {
    id: true,
    label: true,
    user: true,
    userId: true,
    eventType: true,
    eventTypeId: true,
    days: true,
    startTime: true,
    endTime: true,
    date: true,
  }
})
  

drwb avatar May 22 '22 15:05 drwb

The Prisma schema in the published docker image is a bit old or outdated, I had to access the database through pgadmin and added my first user there.

asantarissy avatar May 24 '22 05:05 asantarissy

Given I’m building locally with docker compose build calcom is there a possibility of updating the schema in the local repository before the build?

drwb avatar May 24 '22 12:05 drwb

You may have a database volume leftover from a previous setup. Is this a fresh instance? If you need to start from scratch, you can find the database-data volume and delete it docker volume ls docker volume rm {name of offending volume}

I am working now on getting the updated image pushed, so you can try running locally without building

krumware avatar May 25 '22 15:05 krumware

@drwb that updated image has been pushed. I know we're working through other things, but in the context of this particular issue, were you able to use the image to run the migration?

krumware avatar Jun 03 '22 13:06 krumware

Currently the same issue appears with another column:

Prisma Studio says: The column Booking.confirmed does not exist in the current database.

Software-Design avatar Jun 07 '22 09:06 Software-Design

Type: undefined Message: Invalid prisma.user.create() invocation:

The column Booking.confirmed does not exist in the current database.

Code: P2022

Query: [object Object]

Getting exactly the same error when creating a user

YBAAC avatar Jun 09 '22 10:06 YBAAC

Same error here with last update at main branch

Prisma Studio says: The column Booking.confirmed does not exist in the current database.

marcoadasilvaa avatar Jun 15 '22 01:06 marcoadasilvaa

For the ones needing a quick solution, I just used pgAdmin4 temporarily to create an user:

  pgadmin:
    container_name: pgadmin4_container
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - 127.0.0.1:5050:80
    depends_on:
      - database
    networks:
      - stack

cderszteler avatar Jun 15 '22 14:06 cderszteler

Also seems to be happening on destinationCalendar

`Message: Error in Prisma Client request:

Invalid prisma.destinationCalendar.findMany() invocation:

The column DestinationCalendar.bookingId does not exist in the current database.`

It follows with "Unable to run script" error

howephillip avatar Jul 21 '22 21:07 howephillip

Following error is thrown while trying to create first user.

Type: undefined
Message: 
Invalid `prisma.user.create()` invocation:


  The column `DestinationCalendar.bookingId` does not exist in the current database.

Code: P2022

Query:
[object Object]

Have already tried troubleshooting steps. Also removed past volume to have fresh start as advised earlier.

deepak-lather-v0746 avatar Jul 29 '22 17:07 deepak-lather-v0746

It's seems like a faulty migration on our side. Investigating...

zomars avatar Jul 29 '22 20:07 zomars

Same error here @zomars Any progress on this?

timowevel1 avatar Aug 03 '22 15:08 timowevel1

Having a very similar issue with the migrations, image

Any updates?

samjaninf avatar Aug 30 '22 00:08 samjaninf

@zomars

krumware avatar Aug 30 '22 18:08 krumware

This should be already fixed on latest release.

zomars avatar Aug 30 '22 18:08 zomars

Hey,

I did prune everything from docker and pulled new. But I got this also:

Message: Error in Prisma Client request: 


Invalid `prisma.user.findMany()` invocation:


  The column `DestinationCalendar.bookingId` does not exist in the current database.
  
Query:
{
  "modelName": "User",
  "operation": "findMany",
  "args": {
    "take": 100,
    "skip": 0,
    "select": {
      "id": true,
      "username": true,
      "name": true,
      "email": true,
      "emailVerified": true,
      "password": true,
      "bio": true,
      "avatar": true,
      "timeZone": true,
      "weekStart": true,
      "startTime": true,
      "endTime": true,
      "bufferTime": true,
      "hideBranding": true,
      "theme": true,
      "createdDate": true,
      "trialEndsAt": true,
      "eventTypes": true,
      "credentials": true,
      "teams": true,
      "bookings": true,
      "schedules": true,
      "defaultScheduleId": true,
      "selectedCalendars": true,
      "completedOnboarding": true,
      "locale": true,
      "timeFormat": true,
      "twoFactorSecret": true,
      "twoFactorEnabled": true,
      "identityProvider": true,
      "identityProviderId": true,
      "availability": true,
      "invitedTo": true,
      "plan": true,
      "webhooks": true,
      "brandColor": true,
      "darkBrandColor": true,
      "destinationCalendar": true,
      "away": true,
      "allowDynamicBooking": true,
      "metadata": true,
      "verified": true,
      "role": true,
      "disableImpersonation": true,
      "impersonatedUsers": true,
      "impersonatedBy": true,
      "apiKeys": true,
      "accounts": true,
      "sessions": true,
      "Feedback": true
    }
  }
} 

or

Type: undefined
Message: 
Invalid `prisma.user.create()` invocation:


  The column `DestinationCalendar.bookingId` does not exist in the current database.

Code: P2022

Query:
[object Object]

Pamalosebi avatar Sep 01 '22 15:09 Pamalosebi

I can confirm latest release has a mismatch between the Prisma schema and the schema in place for real. By looking at the long history of this issue, I guess the use of Primsa is a sub-optimal idea to add an user.

I suggest everyone that faces a similar issue to solve it via CLI by doing the following in the postgres machine:

# psql -U [DB_USERNAME] -d [DB_NAME] -c "INSERT INTO users (username, name, email, password, metadata) VALUES ('[USER]', '[NAME]', '[EMAIL]', '[BCRYPT-HASH]', '{}');"

If you're here and you're a docker newbie, basically what you need to do is to execute the following while the containers are running:

$ docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS         PORTS                              NAMES
01e594e7c225   calcom-docker_calcom       "docker-entrypoint.s…"   9 seconds ago    Up 8 seconds   0.0.0.0:3000->3000/tcp             calcom-docker_calcom_1
104705ba8b4e   calendso/calendso:latest   "docker-entrypoint.s…"   9 seconds ago    Up 8 seconds   3000/tcp, 0.0.0.0:5555->5555/tcp   calcom-docker_studio_1
5f873249c74b   postgres                   "docker-entrypoint.s…"   10 seconds ago   Up 9 seconds   5432/tcp                           database

Collect the Container ID of the postgres database and use it to get a shell inside the container:

$ docker exec -it 5f873249c74b bash

afterwards, just execute the following query, by paying attention to replace every field with your desired data:

# psql -U unicorn_user -d calendso
psql (14.5 (Debian 14.5-1.pgdg110+1))
Type "help" for help.
calendso=# INSERT INTO users (username, name, email, password, metadata) VALUES ('user', 'user', '[email protected]', '$2a$12$gRhRo3xgNaHziqGweOHBv.YgF6LGf3QjE8T5h5HxqwTfH.6NHeRtO', '{}');
INSERT 0 1

xoda avatar Sep 04 '22 18:09 xoda

@zomars can you take a look?

PeerRich avatar Sep 04 '22 20:09 PeerRich

just to confirm @xoda did you try this? https://developer.cal.com/self-hosting/database-migrations

PeerRich avatar Sep 04 '22 20:09 PeerRich

@PeerRich I didn't, but since I pulled everything from scratch just yesterday, I assumed everything was up-to-date and I had no reason to update the database. If it's not the case I can help testing it out.

xoda avatar Sep 05 '22 05:09 xoda