-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Rename column with long name and index result in postgres error #12585
Comments
The problem is that rails is trying to create an index for this new column, and it's named This will raise It's not a Rails issue. Thanks. |
Thanks for these informations @laurocaetano . Actually, a workaround could be to rescue the line which rename the column but this is not really elegant and I would think it could be good to add a way to prevent this in Rails ? |
@bobbus I'm not sure we can prevent this problem completely. If you have to work with very long table / field names It would be best to specify the index names. This way Rails won't rename them when you rename a field. Also you can pick shorter index names as Rails would. EDIT: This is not really a problem of |
I got same problem, so I monkey patched index_name method like this module ActiveRecord
module ConnectionAdapters
module SchemaStatements
def index_name_with_length(table_name, options)
name = index_name_without_length(table_name, options)
name = name[0..63] if name.length > 64
name
end
alias_method_chain :index_name, :length
end
end
end |
Closing this one, as commented in #13209 (comment) Thanks guys. |
@laurocaetano , I can understand that we do not want the fix in #13209 in Rails but I believe a better error message or a warning would be useful. The actual error message is a bit brittle, don't you think ? Also, I'm wondering which fix you would recommend in the case of |
@bobbus I agree that the error message is a bit brittle. We could work on improving the error message instead of preventing the error, what do you think? cc @rafaelfranca |
@bobbus what is the full error you get? If possible I'd like to forward the error from the database to the user. It signals that it's not a Rails limitation but something related to the DB backend. Of course that only works if the error links to the cause. |
In Rails 4, an error is raise when we rename a column with an index to a too long name.
Error stack :
An app with the failure could be found here, relevant commit is : bobbus/testing-rails4@4296e5d
The text was updated successfully, but these errors were encountered: