Rake migrate ignores ':null => false' on mysql

I wanted to add a login string column to an existing table
=> I created a migration :


def self.up
add_column “members”, “login” , :string, :null => false
end

remark: it shouldn’t work, as the table is not empty (=> ‘login’ would
be null in the existing rows.)

problem:
rake migrate didn’t complain and executed the migration, but didn’t add
‘not null’ constraint.
(I expected an SQL error here)

Bug? Feature? Limitation?

Alain

Lou
> it worked as advertised for me–migrations added NOT NULL.
>
> if you fail to specify a default you end up with ‘’ as the default
value.
> I added field ‘eye_color’ to my ‘users’ table using migrations,
and got:

Was the table empty, before you ran the migration?

Alain

it worked as advertised for me–migrations added NOT NULL.

if you fail to specify a default you end up with ‘’ as the default
value.
I added field ‘eye_color’ to my ‘users’ table using migrations, and got:

mysql> show create table users;

| users | CREATE TABLE users (
id int(4) unsigned NOT NULL auto_increment,
login varchar(80) NOT NULL default ‘’,
salted_password varchar(40) NOT NULL default ‘’,
email varchar(60) NOT NULL default ‘’,
firstname varchar(40) default NULL,
lastname varchar(40) default NULL,
salt varchar(40) NOT NULL default ‘’,
verified int(11) default ‘0’,
role varchar(40) default NULL,
security_token varchar(40) default NULL,
token_expiry datetime default NULL,
deleted int(11) default ‘0’,
delete_after datetime default NULL,
created_at datetime default NULL,
logged_in_at datetime default NULL,
updated_at timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
eye_color varchar(255) NOT NULL default ‘’,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

script/about
About your application’s environment
Ruby version 1.8.4 (i386-cygwin)
RubyGems version 0.8.11
Rails version 1.0.0
Active Record version 1.13.2
Action Pack version 1.11.2
Action Web Service version 1.0.0
Action Mailer version 1.1.5
Active Support version 1.2.5
Application root /cygdrive/c/rails/relations
Environment development
Database adapter mysql

mysql -u root -p -e “select version()”
Enter password: *******
±--------------+
| version() |
±--------------+
| 4.1.12-nt-max |
±--------------+

Alain R. wrote:

Lou

it worked as advertised for me–migrations added NOT NULL.

if you fail to specify a default you end up with ‘’ as the default
value.
I added field ‘eye_color’ to my ‘users’ table using migrations, and
got:

Was the table empty, before you ran the migration?

No, and defaults were applied to all records.

Lou V. <vanek@…> writes:

Was the table empty, before you ran the migration?

No, and defaults were applied to all records.

Alain

The same thing happens with postgres adapter. I looked at the source and
it’s most certainly a bug (at least one but two in my opinion). I
actually
“patched” it on my local installation
http://www.redhillconsulting.com.au/blogs/simon/archives/000298.html

Maybe you could do a similar thing until the problem is solved for good.

HTH,

Simon