Skip to content
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() method in migrations is ignoring the name attribute #472

Closed
jrouffiac opened this issue Jul 4, 2021 · 0 comments · Fixed by #474
Closed

unique() method in migrations is ignoring the name attribute #472

jrouffiac opened this issue Jul 4, 2021 · 0 comments · Fixed by #474
Labels
bug An existing feature is not working as intended

Comments

@jrouffiac
Copy link

jrouffiac commented Jul 4, 2021

Describe the bug
Hi Joseph, the recent change to the ORM to allow indexes to be named does not seem to work for unique() - the name I specify is always ignored. index() on the other hand works fine. I tried diving down into the code down to the Table.py class, but I could not see anything obviously wrong.

To Reproduce
For example, as a side project I have started a rewrite of an old (2005) online game of mine. Here is a simplified version (stripped to just the pertinent fields) of the migration for the games table:

...
class CreateGamesTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("games") as table:
            table.increments("id")
            table.string("game_title", length=255, nullable=False)
            table.timestamps()
            # table.index(column="game_title", name="ix_games_game_title")  # <= this works when uncommented
            table.unique(column="game_title", name="uq_games_game_title")   # <= this does not
...

Expected behavior
What do you believe should be happening?
The field games.game_title should have a unique index on it called uq_games_games_title

However, although it does have a unique index, it's ignoring the supplied name and using the default:

SELECT DISTINCT
    TABLE_NAME,
    COLUMN_NAME,
    INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'new_dev'
  AND TABLE_NAME='games';

TABLE_NAME  COLUMN_NAME  INDEX_NAME
games       game_title   games_game_title_unique
games       id           PRIMARY

Desktop (please complete the following information):

  • OS: macOS
  • Version 10.14.6

What database are you using?

  • Type: MySQL

  • Version 8.0.21

  • Masonite ORM 1.0.52

  • PyMySQL 1.0.2

  • Python 3.9.6

Additional context
N/A

@jrouffiac jrouffiac added the bug An existing feature is not working as intended label Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant