Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Both CURRENT_TIMESTAMP and CURRENT_TIMESTAMP(0) as default values result in "Invalid default value" error #10833

Open
1 of 18 tasks
jwiam opened this issue Apr 17, 2024 · 0 comments

Comments

@jwiam
Copy link

jwiam commented Apr 17, 2024

Issue description

When using the CreateDateColumn decorator in TypeORM with MySQL and NestJS, setting CURRENT_TIMESTAMP or CURRENT_TIMESTAMP(0) as the default value results in Invalid default value error. However, setting the default value as CURRENT_TIMESTAMP(6) or providing a precision: 0 option with CURRENT_TIMESTAMP doesn't throw any error.

Expected Behavior

Using CURRENT_TIMESTAMP or CURRENT_TIMESTAMP(0) as default values in CreateDateColumn decorator should not result in an error when synchronizing the database schema.

Actual Behavior

When using CURRENT_TIMESTAMP or CURRENT_TIMESTAMP(0) as default values in CreateDateColumn decorator, an error occurs when synchronizing the database schema:

QueryFailedError: Invalid default value for 'createdAt'

Steps to reproduce

Here are the entity definitions that cause the issue:

@CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
createdAt: Date;

@CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(0)' })
createdAt: Date;

My Environment

Dependency Version
Operating System MacBook Air M2
Node.js version 20.12.2
Typescript version 5.1.3
TypeORM version 0.3.20
NestJS version 10.3.2
nestjs/typeorm version 10.0.2
MySQL version 8.3.0

Additional Context

Using CURRENT_TIMESTAMP in combination with precision: 0 doesn't result in any error:

@CreateDateColumn({ 
  type: 'timestamp',
  precision: 0,
  default: () => 'CURRENT_TIMESTAMP' 
})
createdAt: Date;

I would greatly appreciate any insights or workarounds for this issue. This report was composed with the help of an AI Assistant.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant