Paul
05/29/2021, 4:46 PMJack
05/29/2021, 9:05 PMTom
05/30/2021, 6:17 AMError in HTTP Request (Status: 401) {}
It's probably something with authentication. If I enter the wrong password I don't see this error popup but the login window clears. So the reason for this error are not invalid credentials. In the logs I can see this:
{
"level": "error",
"ts": 1622364163.8549633,
"logger": "http.log.access",
"msg": "handled request",
"request": {
"method": "POST",
"uri": "/api",
"proto": "HTTP/1.1",
"remote_addr": "10.123.123.123:54321",
"host": "<http://prisma.mydomain.com|prisma.mydomain.com>",
"headers": {
"Content-Length": [
"220"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Te": [
"trailers"
],
"X-Forwarded-For": [
"123.123.123.123"
],
"Origin": [
"<https://prisma.mydomain.com>"
],
"X-Forwarded-Proto": [
"https"
],
"User-Agent": [
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0"
],
"Accept": [
"*/*"
],
"Accept-Language": [
"en-US,en;q=0.5"
],
"Content-Type": [
"application/json"
],
"Dnt": [
"1"
],
"X-Request-Start": [
"1622366163855563"
]
}
},
"common_log": "10.201.104.156 - - [30/May/2021:06:12:43 +0000] \"POST /api HTTP/1.1\" 401 0",
"duration": 0.00003197,
"size": 0,
"status": 401,
"resp_headers": {
"Server": [
"Caddy"
],
"Www-Authenticate": [
"Basic realm=\"restricted\""
]
}
}
I re-deployed the whole app and tried different browsers and users but always get the same error.
I'm not quite sure if this is a prisma issue but maybe you have an idea how to debug it. Thanks!Jin
05/30/2021, 11:03 AMPlease feel free to send Direct Message 🦜
Gustav Walter
05/30/2021, 11:55 AMconst response = await prisma.product.findUnique({
where: {
name: name,
},
});
and it's complaining about the name type when I try to build, please look at the attached image.
Now it's complaining about the type, the name was originally a string but I changed it to any, but I still can't seem to get it to work.
My model for the product table is:
model Product {
id Int @id @default(autoincrement())
name String @unique
price Int
orderItems OrderItem[]
}
and the error message is:
Type error: Type '{ name: any; }' is not assignable to type 'ProductWhereUniqueInput'.
I'm assuming it has something to do with the @unique part in the table and the type around it.
If anyone know how to solve this, feel free to contact me! 🙂
Thanks
//GustavBeyond
05/30/2021, 3:41 PMJames
05/30/2021, 11:53 PMChris Baucom
05/31/2021, 3:49 AMJulien Goux
05/31/2021, 7:10 AMJulien Goux
05/31/2021, 7:10 AMIbad Shaikh
05/31/2021, 7:23 AM$transaction
query.
My current code (which is not working yet) :
const _users_ = _await prisma.user.findMany_({
_select_:_ _{ _id_: _true_, _username_: _true_ },
_ _})
_for_ (const _u_ of users) {
let_ _uniqueId_ _= _nanoid_()
_await_ _prisma.user.update_({
where: { id: parseInt(_u._id) },
data: {
reference_code: uniqueId +
-${_u._username}` + -${_u._id}
,
},
})`
}
_await_ _prisma.$transaction_([users])
Actually I want to update each user's reference_code ,for which I need its id and username.
How to access the id and username of the user which im currently updating?
From the docs I read that its not possible to grab id from find and the use it in update query.
How can I solve this?Harun
05/31/2021, 10:57 AMDaniel Olavio Ferreira
05/31/2021, 11:02 AMDaniel Olavio Ferreira
05/31/2021, 11:03 AMAlbert Luft
05/31/2021, 2:26 PMmult-field id
:
I have two tables, generic_articles
and translations
. Multiple articles can have the same name, so generic_article_name
is not @unique
, and one generic_article_name
returns all translations for that name, making it a many to many relationship.
model generic_articles {
generic_article_id Int @id
generic_article_name Int
generic_article_names generic_article_names[]
}
model translations {
term_id Int
language_id Int
term String @db.VarChar(60)
generic_articles generic_article_names[]
@@id([term_id, language_id])
}
model generic_article_names {
generic_article generic_articles @relation(fields: [generic_article_id], references: [generic_article_name])
generic_article_id Int
translation translations @relation(fields: [term_id], references: [term_id])
term_id Int
@@id([generic_article_id, term_id])
}
I tried following this, but it didn't work out as it needs to reference @id
, but the generic_article_name
is not unique.
Currently I "pretend" for it to be unique and then I find duplicates of the generic_article_name
and put the data manually onto the duplicates.Daniel Esteves
05/31/2021, 3:21 PMBruno Casado
05/31/2021, 5:43 PMjasci
05/31/2021, 8:13 PMfields
on relation
attribute it should refer to the name of the field in the database or in the prisma schema ( if I use @map
on some field, therefore different names in the db and 'schema.prisma' file and want to use it in fields
) ?
@relation(fields: [someFieldName], references: [id])
someFieldName
- field name from 'schema.prisma' or actual db field's name ?
Thank you.Vignesh
05/31/2021, 8:40 PMSELECT id, name from posts where id IN (select post_id from comments where user_id='123');
Ramzi Tannous
05/31/2021, 10:32 PMTharshan
05/31/2021, 10:41 PMTharshan
05/31/2021, 10:41 PMTharshan
05/31/2021, 10:42 PMawait products.data.map(async (product) => {
const productData = {
id: product.id,
active: product.active,
name: product.name,
description: product.description,
image: product.images?.[0] ?? null,
metadata: product.metadata,
}
await db.product.upsert({
where: { id: productData.id },
update: productData,
create: productData,
})
console.log(`Product inserted/updated: ${product.id}`)
})
Tharshan
05/31/2021, 10:42 PMGiorgio Delgado
06/01/2021, 1:48 AMError occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: Some(KnownError { message: "Unique constraint failed on the constraint: `PRIMARY`", meta: Object({"target": String("PRIMARY")}), error_code: "P2002" }), kind: UniqueConstraintViolation { constraint: Index("PRIMARY") } })
Sai Raj
06/01/2021, 4:27 AMChristian Kozalla
06/01/2021, 6:45 AMRemiO
06/01/2021, 8:30 AMjasci
06/01/2021, 8:36 AMparentSalesDomain
How model looks before the last step of the upgrade CLI
model Calendar {
id String @id @default(cuid()) @db.VarChar(30)
...
parentSalesDomain String? @db.VarChar(30)
SalesDomain SalesDomain? @relation(fields: [parentSalesDomain], references: [id])
...
}
How model looks after the last step of the upgrade CLI
model Calendar {
id String @default(cuid()) @id @db.VarChar(30)
...
parentSalesDomainId String? @map("parentSalesDomain") @db.VarChar(30)
parentSalesDomain SalesDomain? @relation(fields: [parentSalesDomain], references: [id])
...
}
I cannot quite understand:
1. Is it allowed for the fields
field of the relation
attribute to reference itself ?
2. What is the role of the @map
attribute here ? We map it to the underlying foreign key and then don't use this field in the relation
What I think it should look like. I'm gonna use the new schema to create a new db from it, so I can rename fields(foreign key before - parentSalesDomain, foreign key now - parentSalesDomainId). Is it the right model definition?
model Calendar {
id String @id @default(cuid()) @db.VarChar(30)
...
parentSalesDomainId String @db.VarChar(30)
parentSalesDomain SalesDomain @relation(fields: [parentSalesDomainId], references: [id])
...
}
Thank you.
P.S.
prisma1 schema
type Calendar {
id: ID! @id
...
parentSalesDomain: SalesDomain!
...
}
Harun
06/01/2021, 10:03 AM