# Migration w/change\_column fails on MySQL 5.1

**URL:** <https://www.ruby-forum.com/t/migration-w-change-column-fails-on-mysql-5-1/90435>\
**Category:** Rails\
**Created:** [March 28, 2007, 8:44pm UTC](https://www.ruby-forum.com/t/migration-w-change-column-fails-on-mysql-5-1/90435 "2007-03-28T20:44:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 28, 2007, 8:44pm UTC](https://www.ruby-forum.com/t/migration-w-change-column-fails-on-mysql-5-1/90435/1 "2007-03-28T20:44:15Z")

</div>

All,

I have a migration with statements like this:

change\_column :quote\_input\_class\_codes, :employee\_payroll, :integer,  
:default =\> 0, :null =\> false

When I migrate, I get:

# (in C:/eclipse/workspace/OnlineRating) == DefaultQiccPayrollsToZero: migrating

– change\_column(:quote\_input\_class\_codes, :employee\_payroll, :integer,  
{:null=\>false, :default=\>0})  
rake aborted!  
Mysql::Error: Data truncated for column ‘employee\_payroll’ at row 1:  
ALTER TABLE quote\_input\_class\_codes CHANGE employee\_payroll  
employee\_payroll int(11) DEFAULT 0 NOT NULL

Notice the duplication of the column name in the generated SQL, which is  
why this is failing.

Anyone seen this before? Is it a known issue?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 28, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/migration-w-change-column-fails-on-mysql-5-1/90435/2 "2007-03-28T21:39:24Z")

</div>

Solutiono: MySQL can’t set columns to NOT NULL if any of their values  
are NULL.

This migration worked fine after all of the NULLs were replaced with  
something.

I verified the ALTER TABLE syntax against the MySQL 5.1 reference manual  
and it was correct.

Thanks,  
Wes
