On Tue, Dec 14, 2010 at 2:39 PM, Marnen Laibow-Koser
<lists@ruby-forum.com> wrote:
>
> "Gustavo de Sá Carvalho Honorato" <gustavohonorato wrote in post
> #968329:
> > Hi,
> >
> > after changing a primary key column name, the auto-increment information
> > (MySQL) and sequence (Oracle) are lost.
>
> So what? The actual value of the key should never be significant
> anyway.
Sorry Marnen, I think I didn't make myself clear, let me show one
example which ilustrates betteer what I'm trying to say. Consider this
user table, in MySQL database:
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(255) | YES | | NULL | |
| password | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
Look that id column has auto_increment extra.
When I rename :id column using "rename_column :users, :id, :key" my
new :key column loses its "auto_increment" as bellow:
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| key | int(11) | NO | PRI | 0 | |
| username | varchar(255) | YES | | NULL | |
| password | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
>
>
> > What is the correct way to
> > rename
> > primary keys?
>
> rename_column :table, :key, :id
>
> >
> > Thanks,
> > Gustavo
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> marnen@marnen.org
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment