Athir Nuaimi
12/11/2021, 6:00 PMAthir Nuaimi
12/11/2021, 6:00 PMmodel User {
id Int @id @default(autoincrement())
email String @unique
lists List[]
}
model List {
id Int @id @default(autoincrement())
name String
links String[]
ownerId Int?
owner User? @relation(fields: [ownerId], references: [id])
}
Athir Nuaimi
12/11/2021, 6:01 PM[
{ "email" : "<mailto:athir@test.com|athir@test.com>",
"lists" : [
{
"name" : "Italy",
"links" : [
"<https://adventuresoflilnicki.com/southern-italy-road-trip>",
"<https://adventuresoflilnicki.com/things-to-do-matera-italy/>",
"<https://adventuresoflilnicki.com/syracuse-travel-sicily/>",
"<https://eternalarrival.com/rome-itinerary-3-days/>"
]}
]
},
{ "email" : "<mailto:nancy@test.com|nancy@test.com>",
"lists" : [
{
"name" : "Mexico City",
"links" : [
"<https://www.geekyexplorer.com/mexico-city-itinerary/>",
"<https://www.washingtonpost.com/travel/mexico/mexico-city-local-guide/>"
]
}
]
}
]
Athir Nuaimi
12/11/2021, 6:01 PM// read data from json file
const seed_data = <User[]>require("../data/seed.json");
// go through each user
for (const user_data of seed_data) {
// user lists, need 'create' item
let user = await prisma.user.create({
data: {
email: user_data['email'],
lists: {
create: user_data['lists'],
}
},
});
Athir Nuaimi
12/11/2021, 6:02 PM25 console.log(user_data)
26
27 // user lists, need 'create' item
→ 28 let user = await prisma.user.create(
The column `links` does not exist in the current database.
Athir Nuaimi
12/11/2021, 6:02 PMuser_data['lists']
to be just a single element user_data['lists'][0]
it worksMaciek K
12/11/2021, 6:58 PMcreateMany
instead of create
. Try something like this:
for (const user_data of seed_data) {
// user lists, need 'create' item
let user = await prisma.user.create({
data: {
email: user_data['email'],
lists: {
createMany: {
data: user_data['lists'],
}
}
},
});
Athir Nuaimi
12/11/2021, 7:00 PMMaciek K
12/11/2021, 7:01 PMAthir Nuaimi
12/11/2021, 7:01 PMMaciek K
12/11/2021, 7:01 PMAthir Nuaimi
12/11/2021, 7:02 PMstring[]
. I’m not sure what that maps to in postgresAthir Nuaimi
12/11/2021, 7:02 PMMaciek K
12/11/2021, 7:03 PMAthir Nuaimi
12/11/2021, 7:07 PMlinks
as a text array. Did not know postgres has that. I think this is schema issue rather than a create() issueAthir Nuaimi
12/11/2021, 7:07 PMAthir Nuaimi
12/11/2021, 7:09 PMlinks
column and another does not (older schema). I’m going to delete the database and recreate it and then dig into the strings[]
issue.