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.

[Migrations] UNIQUE constraint in Postgres doesn't get removed

See original GitHub issue

Hi! Coming from RoR world, I love this tool!

I ran into a issue, though, with undoing a migration.

when using the Postgres dialect, migrations that want to remove a UNIQUE constraint from a column in fact does not remove it.

Specifically, after one runs the following up() function where ‘MyTable’ already exists and has a ‘my_attr’ column:

up: function (queryInterface, Sequelize) {
  return queryInterface.changeColumn('MyTable', 'my_attr', {
    allowNull: true,
    unique: false,
    type: Sequelize.STRING
  });
}

they will still see UNIQUE CONSTRAINT when running =# \d+ "MyTable" in psql.

Perusing through the code, it seems as if changeColumnQuery() in query-generator.js doesn’t handle removing the unique constraint index at all. It adds it just fine though.

This doesn’t seem like a straightforward fix as you need to first see if an index exists, so I’m documenting the issue… in the hope that someone more familiar with the code to come up with a nice solution 😃

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
aminalali8commented, Jun 1, 2018

Issue on mysql as well

2reactions
Skanthappacommented, May 4, 2018

still an issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove unique constraints from a PostgreSQL DB?
I think the reason is that when the unique constraint is created, PostgreSQL creates an index along with it, and that index doesn't...
Read more >
Documentation: 15: 5.4. Constraints - PostgreSQL
This means that the referenced columns always have an index (the one underlying the primary key or unique constraint); so checks on whether...
Read more >
Postgres - can't drop constraint because objects depend on it ...
The correct solution is to drop the foreign key along with the unique constraint and create it again, so that it points to...
Read more >
23065 (Migration Error when removing unique constraint)
I try to make a migration which simple removes "unique = True" from a field. and get the error below. ... I'm using...
Read more >
Defining Constraints and Indexes
Creating/Dropping Foreign Key Constraints via ALTER; ON UPDATE and ON DELETE. UNIQUE Constraint; CHECK Constraint; PRIMARY KEY Constraint ...
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