[BUG] sequelize.sync ({alter:true}) not altering tables.
See original GitHub issueWhat are you doing?
I have this simple model
const Access_Metric = sequelize.define('access_metric', {
user_id: {
type: DataTypes.INTEGER,
},
}, {
underscored: true,
//tableName: ''
});
return Access_Metric;
};
And I am running a sync.
sequelize.sync({alter: true,
logging:true}).then( status => {
if (status) console.log(status.models);
}).catch(error => console.log(error));
What do you expect to happen?
I expect the table in the database to create a field called user_id.
What is actually happening?
I am receiving an error:
Executing (default): CREATE TABLE IF NOT EXISTS access_metrics
(id
INTEGER NOT NULL auto_increment , user_id
INTEGER, created_at
DATETIME NOT NULL, updated_at
DATETIME NOT NULL, PRIMARY KEY (id
)) ENGINE=InnoDB;
{ DatabaseError [SequelizeDatabaseError]: Duplicate column name ‘created_at’
sqlMessage: “Duplicate column name ‘created_at’”,
sql:
‘ALTER TABLE access_metrics
ADD created_at
DATETIME NOT NULL;’ },
Dialect: mariadb Dialect version: XXX Database version: XXX Sequelize version: v 5.3.5 Tested with latest release: Yes. It was working in the version v 4.42.0, I had to update due to snyk pointing some security issues.
What I think it would be a solution (at least for my case): I have seen you guys removed the use of indexes. Maybe that is why the bug is occurring. I am not sure. Altough we could use the power of MARIADB and:
ALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name tinyint(1) DEFAULT 0; https://stackoverflow.com/questions/972922/add-column-to-mysql-table-if-it-does-not-exist/33755258
Any thoughts on this? I really depend upon this feature specially in fast-paced-one-man-carries-all type of environment. Thank you.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (7 by maintainers)
I will do a bisect tomorrow, hit me up if I forget about it 😅
@iwaduarte I’d also ask you to be patient, we’re working on this in our free time.