frankcollins3 / Next-Water-App

Happy, Healthy Water Cycling App that tracks user/human fluid intake.
https://next-water-app.vercel.app
1 stars 0 forks source link

unique constraint failed fkey_id_index [1:47pm] #101

Closed frankcollins3 closed 11 months ago

frankcollins3 commented 11 months ago

attempting to do: retrieve associative user data from postgres through prisma invocation

🚨 error: 🚨 unique constraint failed fkey_id_index [1:47pm]

proposed approach: already solved. chatGPT couldn't help this out.

    iPROMISEcookies()
    .then( (cookie) => {
      console.log('cookie', cookie)
      axios
      .post('/api/graphql', {
        query: `
        mutation {
          getDailyData(users_id: ${cookie}) {
            google_id
            date
            progress
            weekday
            status
            users_id
          }
        }
        `

chat accurately confirmed had to remove id from graphQL schema. first made the mistake of removing returned endpoints/fields "id" from everything but the Data { } typeDef

solution

        return prisma.data.create({
          data: {
👍             id: dataLength + 1,                      // without this code get a fkey_id_index error.
            google_id: me.google_id || 'no google-id',
            date: dateString,
            progress: 0,
            weekday: dayName,
            status: ['', '', '', '', ''],
            users_id: users_id
          }

solution: remove id from graphQL query & schema & clientside invoke but keep id endpoint within the prisma.create statement.

frankcollins3 commented 11 months ago

problem is that psql isn't catching that it's deleted and thinks it's still in the database. same situation panned out creating login process. Delete a username and the constraint checker: shows that a username that was just removed from psql isn't unique even though there's no data in psql [7:15pm]