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

Add Enum column in migration not working (MySQL) #884

Closed
Kyrela opened this issue Jun 19, 2024 · 3 comments · Fixed by #885
Closed

Add Enum column in migration not working (MySQL) #884

Kyrela opened this issue Jun 19, 2024 · 3 comments · Fixed by #885
Labels
bug An existing feature is not working as intended

Comments

@Kyrela
Copy link
Contributor

Kyrela commented Jun 19, 2024

Describe the bug

When running a migration containing an enum column to add to an existing table, using the MySQL connector, the migration fails.

To Reproduce

  1. Create a MySQL database
  2. Download masonite-minimal.zip, extract files
  3. Replace the config/database.py content with your previously created database information
  4. Open terminal at folder root
  5. Run pip install -r requirements.txt
  6. Run masonite-orm migrate

Expected behavior

The masonite-orm migrate command exit with code 0, the database is updated correctly to reflect the migrations.

Actual behavior

The masonite-orm migrate command exit with code 1, and displays an error code. The last migration is not migrated.

Screenshots or code snippets

Log showed by console:

Migrating: 2024_06_19_201336_test_table
Migrated: 2024_06_19_201336_test_table (0.03s)
Migrating: 2024_06_19_201408_test_enum

  QueryException

  (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL DEFAULT 'foo'' at line 1")

  at .venv\Lib\site-packages\masoniteorm\connections\MySQLConnection.py:176 in query
      172│                     return self.format_cursor_results(cursor.fetchone())
      173│                 else:
      174│                     return self.format_cursor_results(cursor.fetchall())
      175│         except Exception as e:
    → 176│             raise QueryException(str(e)) from e
      177│         finally:
      178│             self._cursor.close()
      179│             if self.get_transaction_level() <= 0:
      180│                 self.open = 0

SQL statement generated by MySQLPlateform (retrived using masonite-orm migrate --show):

ALTER TABLE `test` ADD `test_enum` ENUM NOT NULL DEFAULT 'foo'

SQL statement that should have been generated:

ALTER TABLE `test` ADD `test_enum` ENUM('foo', 'bar', 'baz') NOT NULL DEFAULT 'foo'

Desktop

  • OS: Windows 11 Pro
  • Version: 23H2 (22631.3737)

What database are you using?

  • Type: MySQL
  • Version: Ver 15.1 Distrib 10.11.4-MariaDB
  • Masonite ORM: 2.22.0

Additional context

The src/masoniteorm/schema/platforms/MySQLPlatform.py:add_column_string function simply has no column_constraint format field (as used in src/masoniteorm/schema/platforms/MySQLPlatform.py:columnize_string to fill the values in src/masoniteorm/schema/platforms/MySQLPlatform.py:columnize)

This comment also applies when modifying a existing column, as can be seen in src/masoniteorm/schema/platforms/MySQLPlatform.py:change_column_string, but this function isn't used ; for changed columns, src/masoniteorm/schema/platforms/MySQLPlatform.py:columnize is used instead, as can be seen in src/masoniteorm/schema/platforms/MySQLPlatform.py:compile_alter_sql, so the whole issue doesn't seems to apply when editing a column.

@Kyrela Kyrela added the bug An existing feature is not working as intended label Jun 19, 2024
@Kyrela Kyrela changed the title Add/Edit Enum column in migration not working (MySQL) Add Enum column in migration not working (MySQL) Jun 19, 2024
@josephmancuso
Copy link
Member

can you paste your migration file here?

@josephmancuso
Copy link
Member

your 2024_06_19_201408_test_enum

@josephmancuso
Copy link
Member

nvm i see a zip

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.

2 participants