【发布时间】:2014-07-13 22:39:47
【问题描述】:
我按照本指南了解如何更改主键:
这是我的代码:
class Pk2 < ActiveRecord::Migration
def up
remove_column :contracts, :id # remove existing primary key
rename_column :contracts, :contractId, :id # rename existing UDID column
execute "ALTER TABLE contracts ADD PRIMARY KEY (id);"
end
def down
# Remove the UDID primary key. Note this would differ based on your database
execute "ALTER TABLE contracts DROP CONSTRAINT table_pkey;"
rename_column :contracts, :id, :contractId
add_column :contracts, :id, :primary_key
end
end
我不断收到的错误是“围绕 ALTER TABLE 表添加主键的语法”
请帮忙。谢谢。
【问题讨论】:
-
发布
full error stack。 -
是否成功将
rename:contractId列迁移到:id? -
为什么不尝试成功运行迁移,然后使用
execute命令创建新的迁移?
标签: ruby-on-rails syntax key