Set default value to NOW in the migration doesn't work
See original GitHub issueI have created a migration file:
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('products', {
id: {
type: Sequelize.STRING,
primaryKey: true
},
name: {
type: Sequelize.STRING,
allowNull: false
},
ean: {
type: Sequelize.STRING,
allowNull: false
},
categoryName: {
type: Sequelize.STRING,
allowNull: false,
field: 'category_name'
},
price: {
type: Sequelize.STRING,
},
photo: {
type: Sequelize.STRING,
},
fullUrl: {
type: Sequelize.STRING,
field: 'full_url'
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
allowNull: false,
field: 'created_at'
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
allowNull: false,
field: 'updated_at'
}
}).then(function() {
return queryInterface.addIndex('products', ['ean']);
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable('products');
}
};
the database I’m using is postgressql. when I create the table in this value no default value is set for the column createdAt and updatedAt. is it a bug?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Laravel migration default value - Stack Overflow
The reason why your default value doesnt't work is because the migration file sets up the default value in your database (MySQL or ......
Read more >Set default value to a date field (in migration) - Laracasts
As the title says I'd like to set a default value for a date field inside the migration. I can't change the date...
Read more >How to solve the "doesn't have a default value" error in Laravel
You can edit the migration file and set the dob field to nullable , like so: public function up() {
Read more >Avoid SET/DROP DEFAULT unless a field changes from null ...
You said that "Django uses database defaults to set values on existing rows in a table", but if I migrate my table adding...
Read more >Generated Values - EF Core - Microsoft Learn
You can configure a default value on a property: ... EF Core providers usually don't set up value generation automatically for date/time ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top 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

Hehe no problem, I Solved it doing
defaultValue: Sequelize.fn('now'),Thanks anyways 👍
Sequelize.NOW= blank Default ValueSequelize.fn('now')=CURRENT_TIMESTAMP