postgres fails to use @CreatedDateColumn and @UpdateDateColumn
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.1
(or put your version here)
Steps to reproduce or a small repository showing the problem:
import {
Column,
CreateDateColumn,
UpdateDateColumn,
Entity,
PrimaryGeneratedColumn
} from 'typeorm';
import {
IsNotEmpty,
IsUUID
} from 'class-validator';
@Entity('applications')
export class Application {
@PrimaryGeneratedColumn()
readonly id!: number;
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
updatedAt: Date;
}
saving entity failed { QueryFailedError: null value in column "created_at" violates not-null constraint
at new QueryFailedError (/Users/et/code/NeatCapitalOrg/finicity-service/src/error/QueryFailedError.ts:7:9)
at Query.<anonymous> (/Users/et/code/NeatCapitalOrg/finicity-service/src/driver/postgres/PostgresQueryRunner.ts:170:26)
at Query.handleError (/Users/et/code/NeatCapitalOrg/finicity-service/node_modules/pg/lib/query.js:143:17)
at Connection.connectedErrorHandler (/Users/et/code/NeatCapitalOrg/finicity-service/node_modules/pg/lib/client.js:132:26)
at emitOne (events.js:115:13)
at Connection.emit (events.js:210:7)
at Socket.<anonymous> (/Users/et/code/NeatCapitalOrg/finicity-service/node_modules/pg/lib/connection.js:117:12)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
message: 'null value in column "created_at" violates not-null constraint',
name: 'QueryFailedError',
length: 237,
severity: 'ERROR',
code: '23502',
detail: 'Failing row contains (65, b03e832d-3862-43cb-8e6f-4984378a31a9, null, null).',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'applications',
column: 'created_at',
dataType: undefined,
constraint: undefined,
file: 'execMain.c',
line: '2008',
routine: 'ExecConstraints',
query: 'INSERT INTO "applications"("nc_uuid", "created_at", "updated_at") VALUES ($1, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"',
parameters: [ 'b03e832d-3862-43cb-8e6f-4984378a31a9' ] }
Could not run seed QueryFailedError: null value in column "created_at" violates not-null constraint
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
How can I create columns with type Date and ...
For example (using PostgreSQL): @Column({ type: 'date' }) date_only: ... Last Updated Date, available via @UpdateDateColumn() decorator.
Read more >Documentation: 15: CREATE VIEW
Use the DROP VIEW statement to drop views. Be careful that the names and types of the view's columns will be assigned the...
Read more >Documentation: 15: 19.3. Starting the Database Server
If that variable is not provided either, it will fail. Normally it is better to start postgres in the background. For this, use...
Read more >Documentation: 15: ALTER TABLE
The new default value will only apply in subsequent INSERT or UPDATE commands; it does not cause rows already in the table to...
Read more >Documentation: 15: postgres
Note that this will happen even when within a string literal or comment. But if you use the -j command line switch, a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for checking that @rclayton-the-terrible. I confirmed the same results. Since this is a breaking change, it should be emphasized that people using these decorators need to create a migration to properly set the default to
NOW()
.I just spent something like 6 hours to figure out that my problem was related to an issue closed in 2018. Is there an issue to track the documentation update?