To define mappings between a model and a table, use the `define` method. Sequelize will then automatically add the attributes `createdAt` and `updatedAt` to it. So you will be able to know when the database entry went into the db and when it was updated the last time. If you do not want timestamps on your models, only want some timestamps, or you are working with an existing database where the columns are named something else, jump straight on to [configuration][0] to see how to do that.
To define mappings between a model and a table, use the `define` method.
```js
constProject=sequelize.define('project',{
...
...
@@ -21,7 +20,7 @@ You can also set some options on each column:
```js
constFoo=sequelize.define('foo',{
// instantiating will automatically set the flag to true if not set
The comment option can also be used on a table, see [model configuration][0]
## Timestamps
By default, Sequelize will add the attributes `createdAt` and `updatedAt` to your model so you will be able to know when the database entry went into the db and when it was updated last.
Note that if you are using Sequelize migrations you will need to add the `createdAt` and `updatedAt` fields to your migration definition:
```js
module.exports={
up(queryInterface,Sequelize){
returnqueryInterface.createTable('my-table',{
id:{
type:Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true,
},
// Timestamps
createdAt:Sequelize.DATE,
updatedAt:Sequelize.DATE,
})
},
down(queryInterface,Sequelize){
returnqueryInterface.dropTable('my-table');
},
}
```
If you do not want timestamps on your models, only want some timestamps, or you are working with an existing database where the columns are named something else, jump straight on to [configuration ][0]to see how to do that.
## Data types
Below are some of the datatypes supported by sequelize. For a full and updated list, see [DataTypes](/variable/index.html#static-variable-DataTypes).
...
...
@@ -137,7 +168,7 @@ If you are working with the PostgreSQL TIMESTAMP WITHOUT TIME ZONE and you need