-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to do prisma db seed | help needed #221
Comments
yarn prisma migrate dev |
Hi @kris08052000 , |
Having the same issue @killerkc12. Have been trying to debug for last hour. Even reinstalled the whole project. Still the same error. |
@manavkush Same, even I tried to reinstall the whole project again. |
I think neon db is taking long time to db seed |
External free databases are usually slow. Prefer using the docker postgres setup |
I've been running the command on my local docker postgres container. But the issue persists. Let me try using |
you can refer issue #196 |
Your issue was failing due to a different issue. The error was not the same. |
Hey, @killerkc12 , I'm able to resolve the issue. I think the npx primsa migrate dev already ran the seed file also. Might need to update the Readme file. |
Hi Shubham, Thank you for referring the issue. |
Thank you @manavkush for informing me. |
Yes, understood. I was just saying that because there this problem was being discussed in the comments. |
Ok. Cool. |
i know why this happens, basically when you run |
there was an error in the seed file till yesterday so whoever seeded yesterday got the error and since the fields before the error was already filled, when you ran the seed command it showed unique key error, why this works when you do it with docker today is because the seed issue was fixed today and you must have restarted the docker as well which obviously deletes all contents of the database and when you run docker again the npx prisma db seed ran perfectly the first time itself. why this didnt work with neon/ aiven DB string is because it didnt clear the half filled fields and when you run the command you get the error because there is already some content in the db |
Hi, where timeout is in seconds. Note: Before seeding the db again, make sure to clear the database as some records would have been added during the previous seed and it will throw 'unique constraint error'. |
Just change the package.json file inside the prisma folder.
Let me know if that helps |
You can use npx prisma migrate reset, to reset the db. If any tables are populated, to get rid of the issue |
Don't do this!!! |
Another way is just modifying the code a little bit in the seed.ts the async main function should first check whether there is existingTrack or not and if there is not existingTrack then only it should create the async function main() {
const hashID: any[] = [];
const promises: Promise<any>[] = [];
for (const seed of seedsData) {
// Check if the id already exists in the database
const existingTrack = await db.track.findUnique({
where: { id: seed.data.id },
});
if (!existingTrack) {
// If the id is unique, proceed with the insertion
const promise = db.track.create({ data: seed.data });
promises.push(promise);
hashID.push(seed.data.id);
} else {
console.log(`Track with id ${seed.data.id} already exists.`);
// Handle the situation as needed, e.g., skip insertion, generate a new id, etc.
}
}
await Promise.all(promises); Although there are some nextjs issues but this setups the projects! |
Or you can use |
The steps followed as below:
yarn prisma migrate dev - tables have been created successfully.
yarn prisma db seed - This command is giving the below error
The text was updated successfully, but these errors were encountered: