0

我有一个 Rails 迁移:

>> cat db/migrate/20091126031039_create_cards.rb 
class CreateCards < ActiveRecord::Migration
  def self.up
    create_table :cards do |t|
      t.string :number_hash
      t.int :number
      t.string :name
      t.string :type
      t.string :expiration
      t.int :sec_code

      t.timestamps
    end
  end

  def self.down
    drop_table :cards
  end
end

注意“t.int :sec_code”行。它似乎执行成功:

>> rake db:migrate(in /Users/aaronj1335/Sites/clarkbox)
==  CreateCards: migrating ====================================================
-- create_table(:cards)
   -> 0.4315s
==  CreateCards: migrated (0.4317s) ===========================================

但未创建“sec_code”列:

mysql> describe cards;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment | 
| number_hash | varchar(255) | YES  |     | NULL    |                | 
| name        | varchar(255) | YES  |     | NULL    |                | 
| type        | varchar(255) | YES  |     | NULL    |                | 
| expiration  | varchar(255) | YES  |     | NULL    |                | 
| created_at  | datetime     | YES  |     | NULL    |                | 
| updated_at  | datetime     | YES  |     | NULL    |                | 
+-------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

为什么没有创建 sec_code 列?看来我应该得到一个错误...

4

2 回答 2

2

t.int 应该是 t.integer。试一试。

当有疑问时,头晕总是有一些很好的参考。

于 2009-11-26T03:27:32.557 回答
0

好吧,我也没有看到正确创建的“数字”字段,所以它必须是类型(t.int :number 丢失)

于 2009-11-26T03:29:46.750 回答