P
Prisma6mo ago
fjuk

Date field default value

I have a use case for a date field that has a default value, for the sake of the question, it'll be 1970-01-01. In my prisma file it is set as follows:
field DateTime @db.Timestampz(3) @default(dbgenerated("1970-01-01"))
field DateTime @db.Timestampz(3) @default(dbgenerated("1970-01-01"))
Thr migration itself works just fine, but rverytime I try to create a new migration, it is filled again and again with alter tables for setting the default value ALTER TABLE schema.table_name ALTER COLUMN "field" SET DEFAULT '1970-01-01';
3 Replies
Lord Zd
Lord Zd6mo ago
I would suggest not putting in a default for the date field and handling the the default value in your application. This Git issue explains the issue better than I could. https://github.com/prisma/prisma/issues/19792
GitHub
Unable to set default values in DateTime data type on MySQL · Iss...
Bug description Hi there, I'm in the process of seeing if I can get Prisma to work on our legacy database that has been built on over the years. In the process of pulling the schema and running...
RaphaelEtim
RaphaelEtim6mo ago
Hi @fjuk This is a known bug as you can see from this open issue. You can also try the workaround mentioned in the issue here
GitHub
Issues · prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - Issues · prisma/prisma
GitHub
Migrate creates new ALTER TABLE every single time ran if you use ...
I've added a field that I want set to epoch as the default value last_sent_at DateTime @default("1970-01-01T00:00:00-00:00") I also tried last_sent_at DateTime @default(dbgenerated(&q...
fjuk
fjukOP6mo ago
Thank you
Want results from more Discord servers?
Add your server