Take the 2-minute tour ×

I am trying to run a migration on an existing database to change the column name on a table. When I run the migration, I get an error stating that Blob/Text fields cannot have a default value. The column in question is a text column, with a non-null attribute, but no default value.

The migration that Rails attempts is:


Now, I haven't asked the migration to change the column type, I have only asked it to rename the column, so why is the migration trying to do anything to the column type?

I have Googled the issue, and haven't come up with an explanation or workaround.

Any help appreciated.


share|improve this question

1 Answer 1

up vote 0 down vote accepted

There does seem to be a longstanding unresolved ticket on this issue, as described here:

rails bug report

Rails' default behavior is to make columns which are NULL, since this prevents false positives on presence checks, etc, when translating blank strings back into Ruby. Any chance you can work around this by redefining your text column to work with NULL values in the mySQL console?


You can do this in your migration file, it's not the Rails way but it's a lot nicer than sending an email to everyone to change their local copies:

MyModel.connection.execute "ALTER TABLE xxxxx CHANGE abcd ABCD text DEFAULT NULL"
share|improve this answer
Arrghh the pain! I was trying to do the right thing by NOT going out of the Rails Migration and documenting everything properly so that others could follow, and could just run rake db:migrate. This puts in an extra step external to Rails. Thanks for pointing out the bug report though. I am not sure why I didn't find it. –  Vikram Goyal Jun 9 '09 at 5:45
Thanks, yes, using the execute to do a manual update is much better than external updates. –  Vikram Goyal Jun 9 '09 at 20:55

Your Answer


