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

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Simple is Best asked in Rails

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

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.