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

Preserve collation when changing column in MySQL #45744

Merged
merged 1 commit into from Aug 3, 2022

Conversation

fatkodima
Copy link
Member

Fixes #45742.

@fatkodima fatkodima changed the title Preserve collaction when changing column in MySQL Preserve collation when changing column in MySQL Aug 3, 2022
Copy link
Member

@byroot byroot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. CI is super spotty today though, I restarted it.

@simi
Copy link
Contributor

simi commented Aug 3, 2022

💪

@byroot byroot merged commit a5862af into rails:main Aug 3, 2022
casperisfine pushed a commit to Shopify/rails that referenced this pull request Aug 3, 2022
…lation

Preserve collation when changing column in MySQL
@byroot
Copy link
Member

byroot commented Aug 3, 2022

Backported to 7-0-stable as d60d058

@ahoglund
Copy link
Contributor

ahoglund commented Aug 9, 2022

I'm getting this error:

COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary'

When the change_column is converting from a string type to binary type:

def up
  change_column :column_name, :path, :binary, limit: 1024
end

def down
  change_column :column_name, :path, :string
end

This is because the collation is being preserved when in this case it shouldn't be. According to the MySQL docs the binary type has only one collation also named binary.

I am not sure if there are other special cases that need to be considered like this for column changes. But it seems to me this should be accounted for in code so that migrations don't need to be updated to pass in the collation: "binary" arg to get this working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change_column_null resets collation
4 participants