hi,all.. Here i want to use of migration to create a table and set a defult value for a column..but i cant''t finished.. mycode: class CreateMessages < ActiveRecord::Migration def self.up create_table :messages do |t| t.column :name, :string t.column :content, :text t.column :posttime, :datetime, :default => "now()" end end def self.down drop_table :messages end end it can''t work sucessfully.And the error like this: (in G:/Jc_RubyonRails/InstantRails/rails_apps/guestbook) == CreateMessages: migrating =================================================-- create_table(:messages) rake aborted! Mysql::Error: Invalid default value for ''posttime'': CREATE TABLE messages (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT NULL, `content` text DEFAULT NULL, `posttime` datetime DEFAULT ''now()'') ENGINE=InnoDB (See full trace by running task with --trace) someone could help me.thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2007-Apr-16 00:53 UTC
Re: help:How to set default value for a column use of migration?
Hi, you can do one of the following: t.column :posttime, :datetime, :default => Time.now or t.column :created_at, :datetime Good luck, -Conrad On 4/14/07, Jay <sienpo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hi,all.. > Here i want to use of migration to create a table and set a defult > value for a column..but i cant''t finished.. > > mycode: > class CreateMessages < ActiveRecord::Migration > def self.up > create_table :messages do |t| > t.column :name, :string > t.column :content, :text > t.column :posttime, :datetime, :default => "now()" > end > end > > def self.down > drop_table :messages > end > end > > it can''t work sucessfully.And the error like this: > (in G:/Jc_RubyonRails/InstantRails/rails_apps/guestbook) > == CreateMessages: migrating > =================================================> -- create_table(:messages) > rake aborted! > Mysql::Error: Invalid default value for ''posttime'': CREATE TABLE > messages (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` > varchar(255) DEFAULT NULL, `content` text DEFAULT NULL, `posttime` > datetime DEFAULT ''now()'') ENGINE=InnoDB > > (See full trace by running task with --trace) > > someone could help me.thanks. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---