Skip to content

Throw an error if the user tries to register two models with the same name #15641

Description

@ephys

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Feature Description

Describe the feature you'd like to see implemented

Make the following impossible:

sequelize.define('User');
sequelize.define('User');

The second define should throw an error, because a model named User already exists in sequelize.models.

Describe why you would like this feature to be added to Sequelize

This behavior is dangerous and a source of bugs. Users should remove models manually, and we should ensure that that is possible (i.e. nothing depends on that model), before being able to register a model with the same name.

Example of an issue caused by this: #15639

Is this feature dialect-specific?

  • No. This feature is relevant to Sequelize as a whole.
  • Yes. This feature only applies to the following dialect(s):

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

Activity

  1. added
    type: feature
    pending-approval
    on Feb 3, 2023
  2. removed
    pending-approval
    on Feb 3, 2023
  3. added theissue type on Mar 9, 2025
  4. removed
    type: feature
    on Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions