Connection error when seeding data with Prisma while running migration only

Viewed 825

I created a simple /prisma/seed.js in my project. I followed the error message that instructed me to put commands into my package.json file to support seeding.

After doing the following commands:

npx prisma generate
prisma migrate dev --name init

I get an error, something about my sqlite connection.

 Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
    at cb (/Users/pkellner/repos/pluralsight-building-essential-ui-data-elements-in-react/m8-persisting-to-sql/clip-95-final-old-code/node_modules/@prisma/client/runtime/index.js:38506:17)
    at async main (/Users/pkellner/repos/pluralsight-building-essential-ui-data-elements-in-react/m8-persisting-to-sql/clip-95-final-old-code/prisma/seed.js:62:5) {
  clientVersion: '3.4.2'
}

However, when I then run this command:

npx prisma db seed

My database gets seeded correctly with no errors. Below is my package.json and seed.js files

seed.js

const { PrismaClient } = require("@prisma/client");
const notesData = require("../data/notes.json");
const noteAttributesData = require("../data/noteAttributes.json");
const noteChangeLogsData = require("../data/noteChangeLogs.json");
const tagsData = require("../data/tags.json");
const noteOnTagsData = require("../data/noteOnTags.json");

const prisma = new PrismaClient();


async function main() {
  console.log(`Start seeding ...`);

  for (const rec of notesData) {
    await prisma.note.create({
      data: rec,
    });
  }

  for (const rec of noteAttributesData) {
    await prisma.noteAttributes.create({
      data: rec,
    });
  }

  for (const rec of noteChangeLogsData) {
    await prisma.noteChangeLog.create({
      data: rec,
    });
  }

  for (const rec of tagsData) {
    await prisma.tag.create({
      data: rec,
    });
  }

  for (const rec of noteOnTagsData) {
    await prisma.noteOnTag.create({
      data: rec,
    });
  }


  console.log(`Seeding finished.`);
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });

package.json

   ...
 "dependencies": {
    "@prisma/client": "^3.4.2",
    "axios": "^0.21.1",
    "next": "^12.0.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-toastify": "^7.0.4",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "prisma": "^3.4.2"
  },
  "prisma": {
    "seed": "node prisma/seed.js"
  }
}
0 Answers
Related