Virender Khatri
2013-Nov-17 12:57 UTC
how to create real MySQL timestamp field with default & on update timestamp using rake
Hello,
I am trying to create database using rake and trying to create real MySQL
timestamp fields:
mysql_create_time NOT NULL DEFAULT CURRENT_TIMESTAMP
mysql_default_time NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP
But getting below error:
-----------
$ rake db:schema:load
-- create_table("table_name", {:force=>true})
rake aborted!
Mysql2::Error: Invalid default value for ''mysql_create_time'':
CREATE TABLE
`table_name` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `col1`
varchar(255), `col2` varchar(255), `mysql_create_time` datetime DEFAULT
''CURRENT_TIMESTAMP'' NOT NULL, `mysql_update_time` datetime
DEFAULT
''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'' NOT NULL)
ENGINE=InnoDB
/home/vkhatri/toolkit/db/schema.rb:3:in `block in <top
(required)>''
/home/vkhatri/toolkit/db/schema.rb:1:in `<top (required)>''
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
-----------
It seems timestamp is alias for datetime, not the actual MySQL timestamp
and there is no option to define default values / on update options for
MySQL timestamp field type.
How can i create real MySQL default timestamp and on update timestamp field
using rake/activerecord?
This is my first rails project, please bear with me if i am asking the
wrong question.
Below are my configs:
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
$ rake --version
rake, version 10.1.0
$ rails -v
Rails 4.0.1
$ mysql -V
mysql Ver 15.1 Distrib 5.5.33a-MariaDB, for Linux (x86_64) using readline
5.1
OS: Fedora 19
-----------
# config/databases.yml:
development:
adapter: mysql2
database: toolkit_dev
username: admin
password: admin
host: localhost
test: &TEST
adapter: mysql2
database: toolkit_test
username: admin
password: admin
host: localhost
production:
adapter: mysql2
database: toolkit
username: admin
password: admin
host: localhost
cucumber:
<<: *TEST
-----------
# db/schema.rb file:
ActiveRecord::Schema.define(:version => 20121201) do
create_table "table_name", :force => true do |t|
t.string "col1"
t.string "col2"
t.timestamp "mysql_create_time", :null => false, :default =>
''CURRENT_TIMESTAMP''
t.timestamp "mysql_update_time", :null => false, :default =>
''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP''
end
end
-----------
-v
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.
Peter Vandenabeele
2013-Nov-17 16:18 UTC
Re: how to create real MySQL timestamp field with default & on update timestamp using rake
Hi Virender, You have a better chance of getting help on this list: https://groups.google.com/forum/#!forum/rubyonrails-talk This [rails-core] list is for discussions on the core of the platform. Reference: http://rubyonrails.org/community HTH, peter_v On Sun, Nov 17, 2013 at 1:57 PM, Virender Khatri <vir.khatri@gmail.com>wrote:> Hello, > > I am trying to create database using rake and trying to create real MySQL > timestamp fields: > > mysql_create_time NOT NULL DEFAULT CURRENT_TIMESTAMP > > mysql_default_time NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE > CURRENT_TIMESTAMP > > But getting below error: > > ----------- > > $ rake db:schema:load > > -- create_table("table_name", {:force=>true}) > > rake aborted! > > Mysql2::Error: Invalid default value for ''mysql_create_time'': CREATE TABLE > `table_name` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `col1` > varchar(255), `col2` varchar(255), `mysql_create_time` datetime DEFAULT > ''CURRENT_TIMESTAMP'' NOT NULL, `mysql_update_time` datetime DEFAULT > ''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'' NOT NULL) ENGINE=InnoDB > > /home/vkhatri/toolkit/db/schema.rb:3:in `block in <top (required)>'' > > /home/vkhatri/toolkit/db/schema.rb:1:in `<top (required)>'' > > Tasks: TOP => db:schema:load > > (See full trace by running task with --trace) > > ----------- > > It seems timestamp is alias for datetime, not the actual MySQL timestamp > and there is no option to define default values / on update options for > MySQL timestamp field type. > > How can i create real MySQL default timestamp and on update timestamp > field using rake/activerecord? > > This is my first rails project, please bear with me if i am asking the > wrong question. > > > Below are my configs: > > $ ruby -v > > ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] > > $ rake --version > > rake, version 10.1.0 > > $ rails -v > > Rails 4.0.1 > > $ mysql -V > > mysql Ver 15.1 Distrib 5.5.33a-MariaDB, for Linux (x86_64) using readline > 5.1 > > OS: Fedora 19 > > ----------- > > # config/databases.yml: > > development: > > adapter: mysql2 > > database: toolkit_dev > > username: admin > > password: admin > > host: localhost > > test: &TEST > > adapter: mysql2 > > database: toolkit_test > > username: admin > > password: admin > > host: localhost > > production: > > adapter: mysql2 > > database: toolkit > > username: admin > > password: admin > > host: localhost > > cucumber: > > <<: *TEST > > ----------- > # db/schema.rb file: > > ActiveRecord::Schema.define(:version => 20121201) do > > create_table "table_name", :force => true do |t| > > t.string "col1" > > t.string "col2" > > t.timestamp "mysql_create_time", :null => false, :default => > ''CURRENT_TIMESTAMP'' > > t.timestamp "mysql_update_time", :null => false, :default => > ''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'' > > end > > end > > ----------- > > -v > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/groups/opt_out. >-- Peter Vandenabeele http://www.linkedin.com/in/petervandenabeele https://github.com/petervandenabeele https://twitter.com/peter_v gsm: +32-478-27.40.69 e-mail: peter@vandenabeele.com skype: peter_v_be -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Virender Khatri
2013-Nov-18 01:27 UTC
Re: how to create real MySQL timestamp field with default & on update timestamp using rake
Hello Peter, Thank you for pointing me in the right direction, will post there. Cheers, v On Sunday, November 17, 2013 9:48:36 PM UTC+5:30, Peter Vandenabeele wrote:> > Hi Virender, > > You have a better chance of getting help on this list: > > https://groups.google.com/forum/#!forum/rubyonrails-talk > > This [rails-core] list is for discussions on the core of the platform. > > Reference: http://rubyonrails.org/community > > HTH, > > peter_v > > > > On Sun, Nov 17, 2013 at 1:57 PM, Virender Khatri <vir.k...@gmail.com<javascript:> > > wrote: > >> Hello, >> >> I am trying to create database using rake and trying to create real MySQL >> timestamp fields: >> >> mysql_create_time NOT NULL DEFAULT CURRENT_TIMESTAMP >> >> mysql_default_time NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE >> CURRENT_TIMESTAMP >> >> But getting below error: >> >> ----------- >> >> $ rake db:schema:load >> >> -- create_table("table_name", {:force=>true}) >> >> rake aborted! >> >> Mysql2::Error: Invalid default value for ''mysql_create_time'': CREATE >> TABLE `table_name` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, >> `col1` varchar(255), `col2` varchar(255), `mysql_create_time` datetime >> DEFAULT ''CURRENT_TIMESTAMP'' NOT NULL, `mysql_update_time` datetime DEFAULT >> ''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'' NOT NULL) ENGINE=InnoDB >> >> /home/vkhatri/toolkit/db/schema.rb:3:in `block in <top (required)>'' >> >> /home/vkhatri/toolkit/db/schema.rb:1:in `<top (required)>'' >> >> Tasks: TOP => db:schema:load >> >> (See full trace by running task with --trace) >> >> ----------- >> >> It seems timestamp is alias for datetime, not the actual MySQL timestamp >> and there is no option to define default values / on update options for >> MySQL timestamp field type. >> >> How can i create real MySQL default timestamp and on update timestamp >> field using rake/activerecord? >> >> This is my first rails project, please bear with me if i am asking the >> wrong question. >> >> >> Below are my configs: >> >> $ ruby -v >> >> ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] >> >> $ rake --version >> >> rake, version 10.1.0 >> >> $ rails -v >> >> Rails 4.0.1 >> >> $ mysql -V >> >> mysql Ver 15.1 Distrib 5.5.33a-MariaDB, for Linux (x86_64) using >> readline 5.1 >> >> OS: Fedora 19 >> >> ----------- >> >> # config/databases.yml: >> >> development: >> >> adapter: mysql2 >> >> database: toolkit_dev >> >> username: admin >> >> password: admin >> >> host: localhost >> >> test: &TEST >> >> adapter: mysql2 >> >> database: toolkit_test >> >> username: admin >> >> password: admin >> >> host: localhost >> >> production: >> >> adapter: mysql2 >> >> database: toolkit >> >> username: admin >> >> password: admin >> >> host: localhost >> >> cucumber: >> >> <<: *TEST >> >> ----------- >> # db/schema.rb file: >> >> ActiveRecord::Schema.define(:version => 20121201) do >> >> create_table "table_name", :force => true do |t| >> >> t.string "col1" >> >> t.string "col2" >> >> t.timestamp "mysql_create_time", :null => false, :default => >> ''CURRENT_TIMESTAMP'' >> >> t.timestamp "mysql_update_time", :null => false, :default => >> ''CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'' >> >> end >> >> end >> >> ----------- >> >> -v >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-co...@googlegroups.com <javascript:>. >> To post to this group, send email to rubyonra...@googlegroups.com<javascript:> >> . >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Peter Vandenabeele > http://www.linkedin.com/in/petervandenabeele > https://github.com/petervandenabeele > https://twitter.com/peter_v > gsm: +32-478-27.40.69 > e-mail: pe...@vandenabeele.com <javascript:> > skype: peter_v_be >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.