question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] sequelize.sync ({alter:true}) not altering tables.

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
SimonSchickcommented, Apr 30, 2019

I will do a bisect tomorrow, hit me up if I forget about it 😅

1reaction
SimonSchickcommented, Apr 30, 2019

@iwaduarte I’d also ask you to be patient, we’re working on this in our free time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why aren't my tables being altered when I run sequelize.sync()?
Table.sync({alter: true}). This will alter the table to fit into the new models, but please note that this may cause some data to...
Read more >
How to use 'sequelize.sync()' without difficulties - Medium
With 'force' option, however, it will alter the table, which means you can fully sync between model schema you defined and database.
Read more >
Learning the Sequelize sync method - Nathan Sebhastian
With the alter: true option, the following SQL statement will be executed: CREATE TABLE IF NOT EXISTS ` ...
Read more >
An elegant guide to Sequelize and Node.js -- newline
Each attribute will pair to a column in our database ... A column for the title of our book ... await sequelize.sync({ alter:...
Read more >
Model Basics | Sequelize
This name does not have to be the same name of the table it represents in the ... As shown above, sync({ force:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found