So I’ve a user model and a corresponding table (users) with fields: User_id, username, password etc.
But then I added invitation_limit to users table. Newly created users have invitation_limit, however the users created before the invitation_token migration was run don’t have the invitation_limit field.
How do I update the previously created users to include invitation_token field? Mind you I’m not talking about adding invitation_limit field to users table (i.e. migration), but rather updating already created users.
Thanks,
Seed data shouldn’t be put in a migration. Migrations are for creating structure, not adding data, and you’ll run into problems if you ever move the database.
You could write a rake task. If you create an instance method called something like “generate_invitation_token”, you can then write a rake task like this:
You can then call the rake task from the commandline like this:
This is a cleaner way to do it.
UPDATE
I’ve expanded this answer in a blog post called “Adding Columns and Default Data To Existing Models“.