mysql - Adding new field to pre-existing table and modifying previously created data in Rails -


Then I have a user model with field and related table (user): User_id, username, password etc.

But then I added users_imit_imit to the user table. Newly created users are invite_limit, although the user created before the invitation_token migration did not have an invitation_mit field.

How can I update previously created users to include the invitation_token field? Note that I am not talking about adding the invitation_limit field for the users table (i.e. migration), but updating users already created.

Thanks,

Seed data should not be kept in migration. The migration structure is for creating, not adding data, and if you ever move to the database, you will participate in problems.

You can write a rake task if you create an example method called something like "gener_invitation_token", then you can write a rack function like this:

  # Lib / tasks / invitation_tokens.rake Namespace: Seed "Generate an invitation token for users who are not already" function: user_tokens = & gt; : Environmental User.all (: conditions = & gt; {: invitation_token = & gt; Nil}). Every user You can call the Rock work from the command line in this way:  
  rake seed: user_tokens    / Pre> 

This is a cleaner way of doing this.

UPDATE

I named this reply in a blog post "".


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -