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
Mysql2::Error occured when execute migration datetime column with default option in Rails 7.0 #43292
Comments
Please use t.datetime :registered_at, default: -> { 'CURRENT_TIMESTAMP()' }, null: false Instead |
@intrip Thanks for your reply. |
That's strange, I've tried and it worked. Which version of MySQL are you using? I've tested with 5.7 |
@intrip Hmm... I got an error in both Mysql 5.7.12 and 8.0.26 Through trial and error, I found the following. class CreateTestings < ActiveRecord::Migration[7.0]
def change
create_table :testings do |t|
# add `precision: nil` , migration succeed
t.datetime :registered_at, precision: nil, default: -> { 'CURRENT_TIMESTAMP()' }, null: false
t.timestamps
end
end
end |
@mpg-kaoru-hotate You can pass the desired precision as an argument to t.datetime :registered_at, precision: 6, default: -> { 'CURRENT_TIMESTAMP(6)' }, null: false #42297 changes the default |
@intrip Thank you so much! So, If I made a migration file without setting |
Exactly, if you want to have a lower precision you can as well, as long as the |
@intrip I understand. Thank you so much. |
Steps to reproduce
Then the following error occurs.
In Rails 7.0, Error occurs if you are using MySQL and there is a migration file with datetime columns with default option created in Rails 6.1 or earlier.
Also, if you execute migrate
add_column
orcreate_table
with datetime columns with default option, an error will occur.After the following PR merged, an error has occurred.
#42297
Expected behavior
not failure migration.
Actual behavior
Mysql2 error occurs.
System configuration
Rails version:
v7.0.0 alpha2
Ruby version:
v3.0.2
The text was updated successfully, but these errors were encountered: