Rails 3 迁移:添加参考列? [英] Rails 3 migrations: Adding reference column?

查看:16
本文介绍了Rails 3 迁移:添加参考列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个新的 rails 3 迁移(例如)

If I create a new rails 3 migration with (for example)

rails g migration tester title:tester user:references

,一切正常……但是,如果我添加一列包含以下内容的列:

, everything works fine...however if I add a column with something along the lines of:

rails g migration add_user_to_tester user:references

引用字段未被识别.简而言之,问题是:如何从命令行向 rails 迁移添加引用列?

the reference field is not recognised. In short, the question is: how do I add a referencing column to a rails migration from the command line?

推荐答案

如果您使用的是 Rails 4.x,您现在可以使用引用生成迁移,如下所示:

If you are using the Rails 4.x you can now generate migrations with references, like this:

rails generate migration AddUserRefToProducts user:references

就像您在 rails guides

这篇关于Rails 3 迁移:添加参考列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆