website
website copied to clipboard
Better docs for generating models
I want to make simple table scheme, includes int and datetime types.
However, I just read whole documentation, but couldn't find any helpful information about this issue.
$ sequelize model:generate --name Notes --attributes id:int,text:content,createdAt:datetime,updatedAt:datetime
ERROR: Attribute 'id:int' cannot be parsed: Unknown type 'int'
Fortunately, cli generates some default fields:
$ sequelize model:generate --name Notes --attributes text:content
// results
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Notes', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
content: {
type: Sequelize.TEXT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Notes');
}
};
But it's quite annoying that it's really important thing but there no mentioned about this.
I just found exact type name for "Int" and "Datetime" in attributes from this document: https://github.com/sequelize/cli/blob/master/docs/FAQ.md
$ sequelize model:create --name User --attributes name:string,state:boolean,birth:date,card:integer
Seriously, this information must be added in the document. Or, just put some more helpful information on displaying error, not just telling me you typed wrong type.
Dialect: sqlite Database version: 3.9.2 Sequelize CLI version: 5.2.0 Sequelize version: 4.41.0
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
It seems that 'datetime' is the same as 'date'. A date without time would be dateonly according to the documentation https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
It is really strange that there is no documentation to show an example for each type that can be used with CLI model generate. I don't understand why this has never been documented
I +1 the need for better docs for this