1

I'm used to creating new Rails apps and their schemas from scratch/scaffolding. However I need to hook up this app to an existing postgresql database in AWS that has never previously been hooked up to a rails app and contains a single table.

What's the best way to generate the rails app and model that will contain all of the columns in the database? I'm hoping there's a shortcut as opposed to manually writing a migration and copying each column name/type in.

6
  • You don't need any migration if the database is already there. You only need to create a model, tell the model the table name, and rails will automatically get the attributes of the model inspecting the table's columns. guides.rubyonrails.org/… Commented May 12, 2019 at 22:29
  • But if you actually want to run a test/dev environment with a copy of the existing table you will want a migration to set it up. If its one single table I don't see why you think its a gargantuan task and just writing it manually is probably going to be faster than trying find a working tool to automate the task. Commented May 12, 2019 at 23:09
  • I agree with max... best approach is to create it as a new table as if it has never existed. Then migrate the data after you've created the table. Makes your life a lot easier if you ever want to make changes, or add columns. Commented May 13, 2019 at 5:29
  • Still an interesting question though... what if it was not one but 10 tables with relationships between them... Commented May 13, 2019 at 5:30
  • Seems there's already a thread here: stackoverflow.com/questions/16164542/… Commented May 13, 2019 at 5:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.