Dia TM
11/01/2021, 3:27 PMpostId
column? https://stackoverflow.com/questions/69776608/why-did-the-foreign-key-constraint-fail-on-the-column-postid I described the problem, but there is no answer.Ryan
11/02/2021, 5:56 AMpostId
available when you pass it like this?
postId: faker.datatype.number({ min: 1, max: 7 }),
If not present, then it will throw an error. So make sure that all posts from id 1 to 7 are available.Dia TM
11/02/2021, 7:10 AMimport { PrismaClient, Prisma } from '@prisma/client';
//import faker from 'faker';
const prisma = new PrismaClient();
const faker = require('faker');
const count = 14;
async function main() {
`console.log(Start seeding ...
);`
for (let i = 0; i < count; i++) {
const user = await prisma.user.create({
data: {
email: faker.internet.email(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
avatar: faker.image.avatar(),
},
});
console.log({ user });
}
for (let i = 0; i < count; i++) {
const post = await prisma.post.create({
data: {
title: faker.name.title(),
content: faker.lorem.paragraphs(),
userId: faker.datatype.number({ min: 1, max: 7 }),
},
});
console.log({ post });
}
for (let i = 0; i < count * 2; i++) {
const image = await prisma.image.create({
data: {
imagePuth: faker.image.image(),
postId: faker.datatype.number({ min: 1, max: 7 }),
userId: faker.datatype.number({ min: 1, max: 7 }),
},
});
console.log({ image });
}
`console.log(Seeding finished.
);`
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});