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
Autogenerated migration issue with Rails 7, MySQL and CURRENT_TIMESTAMP #159
Comments
Thanks for reporting the issue. For some reason I wasn't able to reproduce the issue on Rails 7.0.4 and MySQL 8.0.30, for me the migration succeeds, and I can create records that rely on this default value. What versions are you using? |
No worries, and that's interesting. I'm running:
I don't think this is important, but kust in case it helps, I was running |
OK, so the only difference is the minor version of MySQL, I don't know if the recent version happens to fix this issue 🤷🏻♂️. I'm on MacBook M1 (Apple Silicon), I don't know if that makes any difference. You're able to reproduce this in a fresh Rails app? |
Yes, it's very strange 🧐 For the sake of ruling things out, I've just created a completely fresh Rails App and was able to repro this again. I then updated MySQL to 8.0.30 and was still able to repro this (notes below on the commands I ran). It looks like the only other difference is that I'm running an Intel MacBook.
Add to gemfile:
Then repeat the steps above with the same results. |
Thanks for trying it out. It seems there might be differences in MySQL installations, but the documentation clearly states that if a precision is specified for the column type, then the same precision needs to be used for the default value. Instead of adding |
I suspect my MySQL installation was reusing the database created for MariaDB, so I just re-created it locally, and also updated to latest macOS version, and I was able to finally reproduce the issue 🤘🏻 |
Excellent, thanks for responding so quickly. I can also confirm that |
FYI I'm using the latest MySQL 5.7 and Rails 7 and had to use |
3 changes: 1. Changed ids and foreign key columns to use `bigint` instead of `int`. Rodauth (and Rails) now uses `bigint` columns for the ids, so using `int` for the foreign keys doesn't work. 2. Added missing `index` keys for some unique fields to fix `ArgumentError: Unknown key: :unique.` error. 3. Rails now uses precision 6 for `datetime` fields by default, so the default values must also specify that. See [this](janko/rodauth-rails#159).
@zavan I see from your other activity that you're using the Trilogy adapter, which isn't currently being handled here (only mysql2). I can add it to the conditional. |
@janko I had to go back to mysql2 since Sequel doesn't support trilogy, so no worries. Thanks! |
For anyone interested, the Trilogy adapter has landed in Sequel master, so it will be part of the next release. |
Thanks for all the great work on
rodauth-rails
.I've just tried an install on a fresh Rails 7 app using MySQL and caught one small issue, which I've solved but thought it might be helpful to share here.
In the autogenerated migrations for the
accounts
table (db/migrate/xxx_create_rodauth.rb
), there are 3 fields that use theCURRENT_TIMESTAMP
as the default value for datetime fields.When running
rails db:migrate
in Rails 7, this generates an error :I found the solution discussed here on the
rails
repo: rails/rails#43292I was able to make the
rodauth-rails
migrations work by changing the examples like this:to:
The text was updated successfully, but these errors were encountered: