【问题标题】:Migrate Rails Base Table, Table name containing *迁移 Rails 基表,表名包含 *
【发布时间】:2016-06-07 09:04:17
【问题描述】:

我在名为“base_transaction_log.rb”的模型中有一条活动记录。

它的架构信息是:

# Table name: *_bank_transaction_logs
#
#  All bank transaction tables should have the same format.
#
#  id              :integer          not null, primary key
#  credit          :decimal(8, 2)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null

我希望将其中一列 credit 更改为使用 decimal(16,2)。

所以我创建了一个迁移文件并在更改函数中添加了这些行。

change_column :*_bank_transaction_logs, :credit, :decimal, :precision => 16, :scale => 2

这不起作用。

语法错误(rake 中止! 语法错误:/Users/seokhoonlee/Desktop/db/migrate/20160607080159_increase_rest_decimal_precision.rb:81:语法错误,意外的 tIDENTIFIER,期待关键字结束 ...列 :*_bank_transaction_logs, :debit, :decimal, :precisio...)

change_column :base_transaction_logs, :credit, :decimal, :precision => 16, :scale => 2

这也不行。

名称错误(Mysql2::Error: 表 'development.base_transaction_logs' 不存在)

当表是基表(?,我不知道有这个术语)或者它的表名包含*时,如何迁移数据库中的表?

【问题讨论】:

    标签: mysql ruby-on-rails migration


    【解决方案1】:

    通配符的使用被用于子类化Active Record但没有DB支持(它在数据库中不存在)。

    因此,它无法在数据库中找到合适的表。

    就我而言,我必须通过迁移包含 bank_transaction_logs 的任何文件(例如 ABC_bank_transaction_logs)来处理 *_bank_transaction_logs。

    【讨论】:

    • 还有一些用户发布了一个答案并删除了它告诉我用单引号转义特殊字符。如果你的表名中有特殊字符,请用单引号括起来!
    猜你喜欢
    • 2014-02-28
    • 1970-01-01
    • 2013-09-13
    • 2011-09-02
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    相关资源
    最近更新 更多