Seed database with relational fields #2247
-
Hi Im trying to seed a postgres database with country and region. Creating a country is find but I'm getting errors creating the region. Here is my create: const on = await prisma.region.create({
data: { name: 'on', country: { connect: canada } }
}); I keep getting this error: Invalid This schema is straight forward, country is id and name, region is id, name and countryId Heres the full error: {
data: {
name: 'on',
country: {
connect: {
id: 'test id',
createdAt: new Date('2020-04-20T21:23:57.736Z'),
updatedAt: new Date('2020-04-20T21:23:57.736Z'),
name: 'UK'
~~~~
}
}
}
} Unknown arg type CountryWhereUniqueInput {
id?: String
}
Unknown arg `updatedAt` in data.country.connect.updatedAt for type CountryWhereUniqueInput. Available args:
type CountryWhereUniqueInput {
id?: String
}
Unknown arg `name` in data.country.connect.name for type CountryWhereUniqueInput. Did you mean `id`? Available args:
type CountryWhereUniqueInput {
id?: String
} Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, const on = await prisma.region.create({ data: { name: 'on', country: { connect: canada } } }); to const on = await prisma.region.create({ data: { name: 'on', country: { connect: { id: 's4f5d45sd45sd' } } });
// with s4f5d45sd45sd is a Unique Identifier for a field in Country type
// namely *id* in your case Unknown arg name in data.country.connect.name for type CountryWhereUniqueInput. Did you mean id? Available args:
type CountryWhereUniqueInput {
id?: String // <- the only available identifier
} Also, for a straight forward seed file, checkout this example in the docs. You can replace the field with your data (user1 and user 2 to your regions and fields inside posts to your countries ) Hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi,
the error is basically saying that you're trying to connect to a field which is not found.
You cannot connect to canada, instead, you should connect to a reference to canada in your database.
Try to change:
to