rake db上的ALTER SEQUENCE:reset db:migrate not working

时间:2014-05-08 16:04:26

标签: ruby-on-rails ruby postgresql database-migration user-management

我正在使用Ruby on Rails开发一个信息系统。

我想向用户分发以下uid:

0: root
1-499: system services (server-side)
500: system admin
501-999: external apps (apps that connect through API)
1000+: human users

我已设置以下迁移:

class SetUsersAutoincrementValue < ActiveRecord::Migration
  def change
    execute("ALTER SEQUENCE users_id_seq RESTART WITH 1000")
  end
end

迁移按预期工作。但是,如果由rake db:reset db:migrate触发,则不会。{/ p>

怎么办?

由于

2 个答案:

答案 0 :(得分:4)

我想rake db:migrate:reset

答案 1 :(得分:0)

尝试重新启动ruby服务器(Puma)可能会有所帮助。

我直接在DB上运行SQL命令ALTER TABLE,以将表ID列从INT更改为BIGINT。

更新后,插入大数字时出现错误out of range for ActiveModel::Type::Integer with limit 4"

重启ruby服务器后,一切正常。

相关问题