Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Activerecord 如何使用外键创建迁移脚本_Activerecord_Ruby On Rails 2 - Fatal编程技术网

Activerecord 如何使用外键创建迁移脚本

Activerecord 如何使用外键创建迁移脚本,activerecord,ruby-on-rails-2,Activerecord,Ruby On Rails 2,我想通过迁移脚本创建带有外键的表 create_table :posts do |t| t.string :title end create_table :comments do |t| t.references :post end 在rakedb:migrate之后,post没有通过id引用注释 如何在rails-2.2.3中创建此功能?您可以将迁移创建为普通表模式,并使用:primary\u key option for bellings\u to以更广泛地支持旧模式和使用单独外

我想通过迁移脚本创建带有外键的表

create_table :posts do |t|
  t.string :title
end

create_table :comments do |t|
  t.references :post
end
rakedb:migrate
之后,post没有通过id引用注释


如何在rails-2.2.3中创建此功能?

您可以将迁移创建为普通表模式,并使用:primary\u key option for bellings\u to以更广泛地支持旧模式和使用单独外键的模式:


属于:posts,:foreign\u key=>“post\u id”

我想在数据库级别执行此操作。