pguardiario
pguardiario

Reputation: 54984

generate activerecord schema from an existing table

Does anyone know of a way to do this?

I have an existing table that I created with sql and I would like to create a schema from it that would reproduce the table (minus the data)

Upvotes: 6

Views: 3366

Answers (2)

Anand Shah
Anand Shah

Reputation: 14913

  1. Edit config/database.rb to point to the database you want copied.
  2. rake db:schema:dump
  3. Create a blank migration
  4. Copy the relevant create_table lines from the schema dump and paste it into the migration file
  5. Manually insert the migration timestamp into schema_migrations table (this applies to existing setup only as it already has the relevant table)

Upvotes: 11

Sarun Sermsuwan
Sarun Sermsuwan

Reputation: 3818

A schema is written in [your app]/db/schema.rb. Hope this help!

Upvotes: -2

Related Questions