generate activerecord schema from an existing table

前端 未结 2 774
清歌不尽
清歌不尽 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)
    0 讨论(0)
  • 2020-12-19 09:16

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

    0 讨论(0)
提交回复
热议问题