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

Altar table fails against MySQL, possibly invalid SQL generation #6053

Closed
verdverm opened this issue Apr 3, 2024 · 2 comments
Closed

Altar table fails against MySQL, possibly invalid SQL generation #6053

verdverm opened this issue Apr 3, 2024 · 2 comments

Comments

@verdverm
Copy link

verdverm commented Apr 3, 2024

Environment

Knex version: knex@3.0.1
Database + version: mysql2@3.6.2 | MySQL 8.3.0
OS: mac m2

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do

  2. Error message

  3. Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
    database connection to MySQL or PostgreSQL, then single file example which initializes
    needed data and demonstrates the problem.

I'm getting an error from a migration that happens here: https://github.com/strapi/strapi/blob/cb634392313a5a8089523ac32c51e41326dc579b/packages/core/database/src/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.ts#L47

snippet:

await knex.schema.alterTable(tableName, async (table) => {
  debug(`renaming column ${full.columnName} to ${short.columnName}`);
  table.renameColumn(full.columnName, short.columnName);
});

Error:

error="incompatible type for default value: error: 'NULL' is not a valid value for 'double'"
query="alter table `admin_permissions_role_links` change `permission_order` `permission_ord` double NULL DEFAULT 'NULL'"

This query fails in raw SQL, likely because the 'null' in quotes

mysql> create table t (i int);
Query OK, 0 rows affected (0.0198 sec)
mysql> alter table t change i double null default 'null';
ERROR: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'double null default 'null'' at line 1
mysql> alter table t change i ii double null default 'null';
ERROR: 1067: Invalid default value for 'ii'

(working without quotes)

mysql> alter table t change i ii double null default null;
Query OK, 0 rows affected (0.0300 sec)

Records: 0  Duplicates: 0  Warnings: 0
@verdverm
Copy link
Author

verdverm commented Apr 3, 2024

I'm guessing the issue is here:

if (column.Default !== void 0 && column.Default !== null) {

@verdverm
Copy link
Author

verdverm commented Apr 4, 2024

This issue seems to be a product of Dolt returning 'NULL' in quotes from a show table query.

They fixed it there: dolthub/go-mysql-server#2433

@verdverm verdverm closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant