8000 `changeCollation()` will change `DEFAULT NULL` to `DEFAULT 'NULL'` sometimes · Issue #301 · lulco/phoenix · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
changeCollation() will change DEFAULT NULL to DEFAULT 'NULL' sometimes #301
Open
@mbolli

Description

@mbolli

When using

    protected function up(): void {
        $this->changeCollation('utf8mb4_general_ci');
    }

I encountered this for some tables:

 [Phoenix\Exception\DatabaseQueryExecuteException (1067)]
  SQLSTATE[42000]: Invalid default value for 'lang'. Query ALTER TABLE `{someTable}` CHANGE COLUMN `lang` `lang` varchar(2) CHARACTER SET
  utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'NULL'; fails

The column had DEFAULT NULL before. It only fails because the lang field only allows 2 characters. The changeCollation() method therefore changed many columns to DEFAULT 'NULL', which is obviously wrong.

I did not really find out why it's the case, but I changed the ColumnSettings::getDefault() method to the following, which is probably wrong but works:

    /**
     * @return mixed
     */
    public function getDefault()
    {
        if (isset($this->settings[self::SETTING_DEFAULT])) {
            $default = $this->settings[self::SETTING_DEFAULT];
            if ($default === 'NULL') {
                return null;
            }
            return $default;
        }
        return null;
    }

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

      0