Field createdAt doesn't have a default value Issue
See original GitHub issueIssue type:
[ ] question [x ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[x ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I define my User.ts
createdAt field in the following way
@CreateDateColumn({ name: 'createdAt', type: 'datetime' })
createdAt: Date
If I try to create a new user via the following code
...
sampleUser.createdAt = new Date()
...
await getRepository(User).save(sampleUser)
I get this error:
UnhandledPromiseRejectionWarning: QueryFailedError: ER_NO_DEFAULT_FOR_FIELD: Field 'createdAt' doesn't have a default value
I went into node_modules typeorm code and console logged the query and the params:
[ 'test@test.com',
'John Doe',
'hashedpass',
'salt',
'test',
1,
'admin' ] /// the createdAt field is missing?
Here is the definition of the createdAt
property in my sql table:
`createdAt` DATETIME NOT NULL,
The query looks good, but the field createdAt
is missing from the params.
- The errors should log more details, like the full query and the full params. Some errors are so general that I have no idea where to start debugging.
- I’m working on an existing database and I don’t want to run sync, so my table doesn’t have a default value for the
createdAt
field. Still, I should be able to set my own createdAt field in the code. I fail to understand why something so basic, simple and so straightforward fails?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
"Field 'createdAt' doesn't have a default value" after ... - GitHub
The problem is that the cli updates the model but doesn't keep track of the added columns and thus umzug doesn't know of...
Read more >ERROR 1364: Field 'createdAt' doesn't have a default value
sequelize createdAt. updatedAt defaultValue 설정하기.
Read more >Field 'created_date' doesn't have a default value
I was trying to add a created_date field but get error while inserting sql through data.sql. However, I got the error 'Field 'created_date' ......
Read more >Field 'updated_at' doesn't have a default value error on server
Right now I'm trying to save a product but I'm getting this error General error: 1364 Field 'updated_at' doesn't have a default value...
Read more >Broken migration due to Field 'created_at' doesn't have a ...
The problem is caused by the field created_at having no default value. This results in a database migration failure.
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
@CreateDateColumn
uses database leveldefault
to generate a new timestamp. So, you can’t use this decorator without any changes to the database schema.Without using the “skipping” way shown in this issue’s title, the same issue is also happening with MySQL and MariaDB also.
It also happens with
@UpdateDateColumn
decorator.