[Ror-es] problema con migraciones y primary key

Daniel Rodriguez Troitiño notzcoolx at yahoo.es
Wed Jul 4 09:17:10 GMT 2007


On 7/4/07, Ruben Colina <ruben.colina at gmail.com> wrote:
> >En principio, no aparece ninguna forma directa usando create_table, sin
> >embargo tienes 2 opciones:
> >Generar el create "a mano", usando execute y la sql
> >Dejarlo como dijimos y añadirle un índice único usando:
> > add_index(:establecimientos, :archivo, :unique => true)
>
> gracias Moises, me gusto la segunda forma pero consegui una forma que me
> parece un poco mejor, lo que hice es lo siguiente y me funciono
> perfectamente:
> class CreateEstablecimientos < ActiveRecord::Migration
>   def self.up
>     create_table :establecimientos, :id => false do |t|
>            .
>            .
>            .
>     end
>            execute "ALTER TABLE establecimientos ADD PRIMARY
> KEY(\`archivo\`)"
>     end
>
>   def self.down
>     drop_table :establecimientos
>   end
> end
>
> GRACIAS por la ayuda!!!
>
>
> --
> Ruben Colina
> Debian GNU/Linux User
>
> "Those who are enamored of practice without theory are like a pilot who goes
> into a ship without rudder or compass and never has any certainty where he
> is going. Practice should always be based on a sound knowledge of theory."
> _______________________________________________
> Ror-es mailing list
> Ror-es at lists.simplelogica.net
> http://lists.simplelogica.net/mailman/listinfo/ror-es
>
>

El tipo de una columna no tiene porque ser un símbolo, de forma que
puedes utilizar una cadena y Rails lo utilizará:

t.column 'archivo', 'integer primary key'

Esa línea definiría una columna llamada archivo que fuera de tipo
integer y además clave principal.

Suerte.


More information about the Ror-es mailing list