Forum: Ruby on Rails rake migrate ignores ':null => false' on mysql

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B45eab4f18aa1bb2a44d6e657531a642?d=identicon&s=25 Alain Ravet (aravet)
on 2005-12-16 00:09
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
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 Lou Vanek (Guest)
on 2005-12-17 22:58
(Received via mailing list)
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 |
+---------------+
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2005-12-18 00:44
(Received via mailing list)
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
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 Lou Vanek (Guest)
on 2005-12-18 12:30
(Received via mailing list)
Alain Ravet 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.
A944b656e1e9cfd45f1e6714435b0a54?d=identicon&s=25 Simon Harris (Guest)
on 2005-12-18 13:12
(Received via mailing list)
Lou Vanek <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/ar...

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

HTH,

Simon
This topic is locked and can not be replied to.