P
Prisma•7mo ago
Lukas

prisma db push is failing on relation

Hello 👋, when trying to apply a new SQLite schema it throws this error complaining something is wrong with the relation. I hope someone experienced can help me, thanks for taking your time! Error: SQLite database error near "(": syntax error in CREATE TABLE "sessions" ( "session_token" TEXT NOT NULL, "user_id" TEXT NOT NULL, "created_at" INTEGER NOT NULL DEFAULT strftime('%s', 'now'), "expires_at" INTEGER NOT NULL, PRIMARY KEY ("user_id", "session_token"), CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE ) at offset 140 0: sql_schema_connector::apply_migration::apply_migration at schema-engine\connectors\sql-schema-connector\src\apply_migration.rs:10 1: schema_core::state::SchemaPush at schema-engine\core\src\state.rs:434 Prisma Schema:
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model roles {
id Int @id @default(autoincrement())
name String
icon String?
description String?
admin_access Boolean? @default(false)
app_access Boolean? @default(false)
users users[]
}

model sessions {
session_token String @unique
user_id String
created_at Int @default(dbgenerated("strftime('%s', 'now')"))
expires_at Int
users users @relation(fields: [user_id], references: [id])

@@id([user_id, session_token])
@@index([user_id], map: "idx_sessions_user_id")
@@index([session_token], map: "idx_sessions_token")
}

model users {
id String @id
first_name String?
last_name String?
display_name String
email String @unique(map: "sqlite_autoindex_users_2")
password_hash String
tfa_secret String?
location String?
title String?
description String?
avatar String?
language String? @default("en-US")
appearance String? @default("auto")
status String? @default("draft")
created_at String @default("datetime('now', 'localtime')")
created_by String
updated_at String?
updated_by String?
last_online String?
role_id Int?
sessions sessions[]
roles roles? @relation(fields: [role_id], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@index([email], map: "idx_users_email")
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model roles {
id Int @id @default(autoincrement())
name String
icon String?
description String?
admin_access Boolean? @default(false)
app_access Boolean? @default(false)
users users[]
}

model sessions {
session_token String @unique
user_id String
created_at Int @default(dbgenerated("strftime('%s', 'now')"))
expires_at Int
users users @relation(fields: [user_id], references: [id])

@@id([user_id, session_token])
@@index([user_id], map: "idx_sessions_user_id")
@@index([session_token], map: "idx_sessions_token")
}

model users {
id String @id
first_name String?
last_name String?
display_name String
email String @unique(map: "sqlite_autoindex_users_2")
password_hash String
tfa_secret String?
location String?
title String?
description String?
avatar String?
language String? @default("en-US")
appearance String? @default("auto")
status String? @default("draft")
created_at String @default("datetime('now', 'localtime')")
created_by String
updated_at String?
updated_by String?
last_online String?
role_id Int?
sessions sessions[]
roles roles? @relation(fields: [role_id], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@index([email], map: "idx_users_email")
}
5 Replies
Lukas
LukasOP•7mo ago
I found out that this is the reason it throws: created_at Int @default(dbgenerated("strftime('%s', 'now')")) is there maybe a way I can handle this differently?
jonfanz
jonfanz•7mo ago
I'm guessing you would like that to be the time at which the model is created?
Lukas
LukasOP•7mo ago
exactly
jonfanz
jonfanz•7mo ago
yup it's just @default(now())
Lukas
LukasOP•7mo ago
Thanks! Is there maybe also a in 30days (any time for that matter) function?
Want results from more Discord servers?
Add your server