我正在使用 Redmine,当我运行 rake db 迁移时,数据库会在 mysql 中创建.我的问题是日期字段错误.我希望它是 mysql 时间戳类型,但它是 MySQL 中的 DATETIME 类型.
class CreateChats此外,如果我对此迁移进行了更改,我该如何让它重新制作表格(删除它不起作用)?
解决方案如果需要,您始终可以插入具有自定义类型的列.符号名称会自动转换为 ActiveRecord 定义的任何内容,但如果您使用纯字符串,则按原样输入:
t.column :ar_timestamp, :timestampt.column :mysql_timestamp, '时间戳'你得到的是 ar_timestamp 是通常的 DATETIME 类型,其中 mysql_timestamp 被定义为 TIMESTAMP.
I am using Redmine and when I run a rake db migration the database gets created in mysql ok. My problem is that the date field is wrong. I want it to be a mysql timestamp type, but instead it is a DATETIME type in MySQL.
class CreateChats < ActiveRecord::Migration def self.up create_table :chats do |t| t.column :message, :string t.column :user, :integer t.column :sendDate, :timestamp end end def self.down drop_table :chats end endIn addition if I make a change to this migration how do I get it to remake the table (deleting it doesn't work)?
解决方案You can always insert a column with a custom type if you want. The symbol names are automatically converted into whatever ActiveRecord defines, but if you use a plain string it goes in as-is:
t.column :ar_timestamp, :timestamp t.column :mysql_timestamp, 'timestamp'What you get is ar_timestamp being the usual DATETIME type where mysql_timestamp is defined as TIMESTAMP.
更多推荐
Ruby/Rails
发布评论