当我跑步
rails g model StripeCustomer user_id:integer customer_id:integer
annotate
# == Schema @R_569_4045@ion
# Table name: stripe_customers
# id :integer(4) not null, primary key
# user_id :integer(4)
# customer_id :integer(4)
# created_at :datetime
# updated_at :datetime
这是否意味着我最多只能保存9,999条记录? (我很惊讶密钥的默认大小多么小).如何在现有表格中将默认ID更改为7位数字?
谢谢.
解决方法:
虽然MysqL客户端的describe命令确实使用显示宽度(请参见docs),但OP问题中的模式信息很可能由annontate_models gem的get_schema_info方法生成,该方法使用每一列的limit属性. limit属性是:binary和:integer列的字节数(请参见docs).
def get_schema_info(klass, header, options = {})
info = "# #{header}\n#\n"
info << "# Table name: #{klass.table_name}\n#\n"
max_size = klass.column_names.collect{|name| name.size}.max + 1
klass.columns.each do |col|
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null
attrs << "primary key" if col.name == klass.primary_key
col_type = col.type.to_s
if col_type == "decimal"
col_type << "(#{col.precision}, #{col.scale})"
else
col_type << "(#{col.limit})" if col.limit
end
#...
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。