schema - add_column for references (Rails) -


I have low rail migration which works perfectly (irrelevant pieces have been removed):

< Pre> create_table: make comments | T | T.text: body t.references: post end

Now I would like to add a author column to my comments table (which User's user), but I do not know how to do this (I just have to write to use execute ).

I see the add_column which does not refer to context . I have actually found it but I do not know how to use it with a add_column statement.

Is this possible? Also, is it true that, for MySQL, does the functionality of "reference" actually do not establish relationships between tables?

However, it is too late to get any of these points, I thought I'd poster The best way to post :) :)

Use change_table instead of create_table To add columns to a table already present with all tables: < / P>

  self.up do change_table: comments do | T | T.references: author end end  

This may look trivial, but other gems such as Devise heavily use their own custom table definitions, and thus you can use them .


Comments