Hello, I am new to PostgreSQL and sequelize so the following might be the intended behavior and not a real issue.
sequelize-automate generates model files that include the id attribute when the dialect chosen is postgres, such as:
const {
DataTypes
} = require('sequelize');
module.exports = sequelize => {
const attributes = {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: "nextval(my_data_id_seq::regclass)",
comment: null,
primaryKey: false,
field: "id"
},
score: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "score"
},
};
const options = {
tableName: "my_data",
comment: "",
indexes: []
};
const MyDataModel = sequelize.define("my_data_model", attributes, options);
return MyDataModel;
};
When inserting a row to the my_data table using my_data_model.insert(payload), we get the error:
Unhandled rejection SequelizeDatabaseError: invalid input syntax for integer: "nextval(my_data_id_seq::regclass)"
Some researching of similar issues show that
- the
id column does not need to be defined in the sequelize model , because ...
- PostgreSQL will automatically handle the auto-incrementing
id column if it exists.
Manually removing the id attribute from the model generated by sequelize-automate appears to get everything working as expected, with sequelize/PostgreSQL automatically populating the id column with an auto-incrementing integer.
Question: If my understanding is correct, sequelize-automate should exclude the id attribute in the models that it generates if using PostgreSQL. Is there an option to do this? Or should sequelize-automate do this automatically?
Thanks again!
Hello, I am new to PostgreSQL and sequelize so the following might be the intended behavior and not a real issue.
sequelize-automategenerates model files that include theidattribute when the dialect chosen ispostgres, such as:When inserting a row to the
my_datatable usingmy_data_model.insert(payload), we get the error:Some researching of similar issues show that
idcolumn does not need to be defined in the sequelize model , because ...idcolumn if it exists.Manually removing the
idattribute from the model generated bysequelize-automateappears to get everything working as expected, with sequelize/PostgreSQL automatically populating theidcolumn with an auto-incrementing integer.Question: If my understanding is correct,
sequelize-automateshould exclude theidattribute in the models that it generates if using PostgreSQL. Is there an option to do this? Or shouldsequelize-automatedo this automatically?Thanks again!