【发布时间】:2015-01-06 18:39:10
【问题描述】:
我需要将一些数据从我们必须的旧网站迁移到新的 Rails 网站。我需要保留我的城市 ID,所以我创建了 id 设置为 false 的表并手动创建了该列:
create_table "cities", id: false, force: true do |t|
t.integer "id", null: false
t.string "name", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "is_active", default: true, null: false
t.string "code_che"
end
add_index "cities", ["id"], name: "index_cities_on_id", unique: true, using: :btree
完成迁移后,我希望能够创建新城市,例如 City.create(name: 'My big city') 但我收到下一个错误:
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint
很明显我犯了一个错误,你能帮我找出哪里吗?我正在使用带有 postgresql gem 的 rails 4。
谢谢。
【问题讨论】:
标签: ruby-on-rails postgresql rails-migrations