Migration doesn't sync with Database
See original GitHub issueBug description
I have been having an issue with the behavior of the @updatedAt, see: Enhance @updatedAt Migration output DDL #7724
Based on a conversation there, I tried alternative solution that looked promising.
Basically, using the @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"))
as a temporary workaround. I know this is a poor use of this feature, but the existing issue is truly becoming a risky problem.
It turns out that it generates the correct SQL, and will solve my problem.
However, it has the side effect of never syncing with the Database. ie: If another migration is run after successfully migrating with this syntax, it just keeps creating a new Migration with all of the same identical changes.
According to your support person, this should still be considered a bug, as it should identify that no changes have been made.
How to reproduce
Change schema
From:
updatedAt DateTime @updatedAt
To:
updatedAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"))
Then run
$ npx prisma migrate dev --create-only
$ npx prisma migrate dev
Then run
$ npx prisma migrate dev --create-only
$ npx prisma migrate dev
Expected behavior
Generates
-- AlterTable
ALTER TABLE `SomeTable ` MODIFY `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3);
One time before actually running the Migration. Changes are made to the database when the Migration is run. Additional migrations indicate no changes, and don’t create any migration files.
Prisma information
Old Table Structure
model SomeTable {
id Int @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
}
Updated Table Structure
model SomeTable {
id Int @unique
createdAt DateTime @default(now())
updatedAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)"))
deletedAt DateTime?
}
Environment & setup
OS: Windows 10 Database: MySQL 5.7 Node: v14.15.3 npm/npx: 6.14.9
Prisma Version
prisma : 3.7.0
@prisma/client : 3.7.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 8746e055198f517658c08a0c426c7eec87f5a85f
Studio : 0.445.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top GitHub Comments
#12574
Your problem is similar, but different enough to justify its own issue. Can you please create one @rojer95 and provide all the information the issue template asks for? Thanks.