1
class CreateTestings < ActiveRecord::Migration
def self.up
create_table :testings do |t|
t.string "name"
t.boolean "visible"
t.string "description"
t.integer "roll"
t.references "students"
t.timestamps
end
end
def self.down
drop_table :testings
end
end
您好,我刚刚运行此测试迁移以查看Rails如何处理Migrations。即使我已经 t.references "students"
Rails迁移未能在MySQL中指定外键表
Rails的创建在我testings表students_id
成功,但是却没有规定它的任何外键:
mysql> DESC testings;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| visible | tinyint(1) | YES | | NULL | |
| description | varchar(255) | YES | | NULL | |
| roll | int(11) | YES | | NULL | |
| students_id | int(11) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
请问这是怎么Rails的作品或以其他方式我应该有
t.references :student
代替t.references "students"
谢谢!
我会假设如果Rails的工作方式,这将是很好的做Rails的方式? – 2011-02-01 04:07:36