generate activerecord schema from an existing table

前端 未结 2 780
清歌不尽
清歌不尽 2020-12-19 08:59

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 (mi

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 09:09

    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)

提交回复
热议问题