Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 520
pguardiario Avatar asked Oct 14 '12 04:10

pguardiario


1 Answers

  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)
like image 100
Anand Shah Avatar answered Oct 17 '22 06:10

Anand Shah