I have a postgresql database that I need to first seed and use predetermine id, then when I create new items to the DB I want the id to auto increment. This was trivial when I was using a SQLite database. When I tried the same code with an PostgreSQL DB I find that the sequelize created IDs have started from zero and have ignored the seedcreated indices, resulting in a unique constraint error.
I figure that this because postgresql uses a separate sequence to keep track of the increment. My approch from here was to use a raw query from sequelize to alter the sequence. But when I try to run an alter sequence query sequelize can't find sequence. I run:
db.query("ALTER SEQUENCE COMPOUND_CPCD_seq RESTART WITH 100;");
But a error is generated and in the error message it states "Unhandled rejection SequelizeDatabaseError: relation "compound_cpcd_seq" does not exist". Is this a problem with upper and lower case letters since COMPOUND_CPCD_seq is not equal to compound_cpcd.seq? And if that is the case how do you work around that (since I have no control over how COMPOUND_CPCD_seq is created)?
What have I missed?
The model:
const COMPOUND= db.define('COMPOUND', {
CPCD: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
unique: true,
},
Name: {
type: Sequelize.STRING,
}
})