New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[unique: true] creates two unique indexes on a column #6134
Comments
UPD 1 Funny thing happens. When you delete
And the result is no redundant index:
Why? I don't want to move indexes to model options. I want to declare them in column definitions. How can I do it without duplications in results? |
Which version does this happen on? |
|
unique columns are added to Line 806 in 47b3f61
|
I'm getting this too -- and I agree that it's an issue. There shouldn't be two unique indexes that are the exact same (only with different names) -- it's completely redundant.
|
I have this problem too |
me too |
I have this problem too. email: {unique: 'email'} |
Had this same problem. @gzlock 's solution worked for me. I agree with others - it's disconcerting to see two nearly-identical indexes being created where you would expect to see one. Seems inefficient. @janmeier - I haven't dived into the code to understand why you're comment about |
@broofa Not being an issue is not specifically related to The comment about |
+1 |
1 similar comment
+1 |
This still happens on version 3.30.4 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂 |
This is still a bug, afaik. |
This is still a bug. |
This is still happening. |
still a bug |
@janmeier is this still a bug? If so I will try to give it a shot, any tips where it is better to start? |
@iaptsiauri yes it is still a bug. you can try a simple example with unique true with mysql. |
still happen in latest version And I found something maybe helpful version formatted sql for reading
CREATE TABLE IF NOT EXISTS `User` (
`id` INTEGER,
`username` VARCHAR(255) UNIQUE,
`password` VARCHAR(255),
UNIQUE `User_username_unique` (`username`),
PRIMARY KEY (`id`)
)
ENGINE = InnoDB; generated indexes:
CREATE TABLE IF NOT EXISTS `User` (
`id` INTEGER,
`username` VARCHAR(255),
`password` VARCHAR(255),
UNIQUE `User_username_unique` (`username`),
PRIMARY KEY (`id`)
)
ENGINE = InnoDB; generated indexes: If use |
Same here, using version |
This is happening for me also, exact issue as Diluka |
I have same issue |
I'm facing this issue but with a foreign key: Model: const Event = sequelize.define('event', {
id: {
type: DataTypes.UUID,
primaryKey: true,
allowNull: false,
defaultValue: DataTypes.UUIDV4
},
createdBy: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'user',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'restrict'
},
// ...
} Migration: return queryInterface.addColumn('event', 'createdBy', {
type: Sequelize.UUID,
allowNull: true,
references: {
model: 'user',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'restrict'
}); Result:
|
For some a reason column option
unique: true
creates two unique indexes on a column. How to prevent it? Please take a look at anemail
field:And here is what is actually created, one unique key on
email
is redundant:Why does it happen? How to prevent it?
The text was updated successfully, but these errors were encountered: