Create a Migration from an existing table?

21 views
Skip to first unread message

RVince

unread,
Nov 15, 2012, 11:01:03 AM11/15/12
to rubyonra...@googlegroups.com
If I have a table in MySQL on an existing Rails project, how do I go to creating a migration for it? All the examples I see online seem to be geared to creating models and tables from a migration -- but how do I go the other way and create a migration itself from a table? Thank you.

Colin Law

unread,
Nov 15, 2012, 11:11:17 AM11/15/12
to rubyonra...@googlegroups.com
Why would you want to create a migration if you already have the table?

Colin

RVince

unread,
Nov 15, 2012, 11:17:40 AM11/15/12
to rubyonra...@googlegroups.com, cla...@googlemail.com
I have to commit my code changes on this specific project and it has to comport to having a migration for a new db table that was required here. I could cobble one by hand, but I think that's even more kludgey! I assume it isn't possible to go from a table to a migration? Thanks.

Walter Lee Davis

unread,
Nov 15, 2012, 11:17:34 AM11/15/12
to rubyonra...@googlegroups.com

On Nov 15, 2012, at 11:01 AM, RVince wrote:

> If I have a table in MySQL on an existing Rails project, how do I go to creating a migration for it? All the examples I see online seem to be geared to creating models and tables from a migration -- but how do I go the other way and create a migration itself from a table? Thank you.

Look in the schema.rb. That's your "up" method, and "down" is always the same: drop_table :foo.

Walter

Reply all
Reply to author
Forward
0 new messages