Skip to main content

[Newbie] How can i keep data while "add field" or "change fieldname" in model?

Rails • Asked by Simple is Best

sorry my english.

if my user model have

t.string :name
t.string :age

and data

1 : John / 34
2 : Tom / 25

if I want to add a field and change field name

t.string :english_name       #change field name
t.string :age
t.string :location                  #add field

rake db:migrate - not work.

rake db:drop
rake db:migrate - working. but John and Tom is gone. RIP

How can i keep data while "add field" or "change fieldname" in model?


Hola! Antes necesitas hacer una migración:

rails generate migration add_name_to_users name:string

De esa manera estás agregando un nombre al modelo User

Fuente:
http://www.peoplecancode.com/es/tutorials/adding-custom-fields-to-devise


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.