One of the most underrated features of Rails is the way it handles proper error messages. It is very easy to understand the error and fix it. If we run a migration and it fails we get an actionable error message that tells us what went wrong and how to fix it. However, when we run a migration that adds a column to a table that already has a column with the same name, the error message that we get is not quite actionable since it does not tell us which table has a duplicate column. In the upcoming version of Rails 7-1, this issue will be fixed.
Before
Let’s create a table which includes two columns named same but of different types -
After we run rails db:migrate
for the above table, the following error is printed in the console -
The above error indicates there cannot be another column named testing_column
because it already exists. This is one table so it’d be easier to debug, but suppose there are multiple migrations being run together and one of the migrations might have duplicate columns then it’d take some of our precious time to debug.
After
In the upcoming version of Rails 7.1, the error will tell us which table name the error comes from.
Look at PR for more information.