创建与迁移轨道缺少自动递增属性 [英] Create missing auto increment attribute with rails migration

查看:158
本文介绍了创建与迁移轨道缺少自动递增属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个迁移到应用程序转换为非轨到合适的格式导轨 - 表由于某种原因没有自动递增的ID列设置之一。有没有一种快速的方法来打开它,而在迁移,可能与 change_column 还是什么?

I'm writing a migration to convert a non-rails app into the right format for rails - one of the tables for some reason does not have auto increment set on the id column. Is there a quick way to turn it on while in a migration, maybe with change_column or something?

推荐答案

您需要执行的SQL语句。

You need to execute an SQL statement.

statement = "ALTER TABLE `users` CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT"
ActiveRecord::Base.connection.execute(statement)

请注意,这只是一个例子。最终的SQL语句的语法取决于数据库。

Note this is just an example. The final SQL statement syntax depends on the database.

这篇关于创建与迁移轨道缺少自动递增属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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