添加编号列在迁移 [英] Add Id column in a migration

查看:131
本文介绍了添加编号列在迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序,其中的车型之一不具有 ID 列。做一些研究,我发现,创建它的迁移:

  CREATE_TABLE(:the_model,:ID =>假)办| T |
  #列
结束
 

现在,一个新的迁移,我想(不使用数据库特定的SQL),添加 ID 列在Rails标准的方式。我该怎么办呢?

我已经试过这没有成功:

  change_table(:the_model,:ID =>真)办| T |
结束
 

解决方案

您可以手动添加ID列:

  add_column:the_model,:ID,:primary_key
 

或清除(或备份)数据,回滚此迁移,摆脱选项:ID =>假,并重新进行迁移。

I have a Rails app, where one of the models does not have the id column. Doing some research I found the migration that created it:

create_table(:the_model, :id => false) do |t|
  # columns
end

Now, on a new migration, I want to add the id column in a Rails standard way (not using database specific sql). How can I do that?

I already tried this without success:

change_table(:the_model, :id => true) do |t|
end

解决方案

You can either manually add the id column:

add_column :the_model, :id, :primary_key

or clear (or backup) your data, rollback to this migration, get rid of the option :id => false, and re-migrate.

这篇关于添加编号列在迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆