为名称中带有数字的列创建迁移 [英] Create Migration for Column with a Number in the Name

查看:66
本文介绍了为名称中带有数字的列创建迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将应用程序移植到rails中,其中两列的名称如下所示:

I'm porting an app into rails and a couple of the columns are named things like

第二个电话 第二个地址

2nd_phone 2nd_address

当我尝试使用进行迁移时 t.string:2nd_phone

When I try doing a migration using t.string :2nd_phone

我收到语法错误,意外的tINTEGER,期待tSTRING_CONTENT或tSTRING_DBEG或tSTRING_DVAR或tSTRING_END

I get syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END

有没有想法如何在集会上做到这一点?

Any ideas how to do this in rals?

推荐答案

在您的迁移文件中,将其引号引起来以将起始字符作为数字1进行支持,然后运行rake db:migrate

In your migration file have this with quotes to support starting character as numeric one and then run rake db:migrate

t.string :'2nd_phone'

这样做时,如果要创建新记录,则需要像这样:

While doing this way if you want to create new record you need to have like this:

Model.create(:'2nd_phone'=> 'your value')

这篇关于为名称中带有数字的列创建迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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