问题描述
我正在将应用程序移植到rails中,其中两列的名称如下所示:
I'm porting an app into rails and a couple of the columns are named things like
第二个电话第二个地址
2nd_phone2nd_address
当我尝试使用进行迁移时t.string:2nd_phone
When I try doing a migration usingt.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')
这篇关于为名称中带有数字的列创建迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!