从现有的表生成的ActiveRecord模式 [英] generate activerecord schema from an existing table
本文介绍了从现有的表生成的ActiveRecord模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道的一种方式做到这一点?
我有我与SQL创建了一个现有的表,我想创建一个从它的模式,将重现表(减去数据)
解决方案
- 编辑配置/ database.rb指向你想复制的数据库。
-
耙分贝:模式:转储
- 创建一个空白的迁移
- 从模式转储复制有关
CREATE_TABLE
行并将其粘贴到迁移文件 - 在手动插入迁移时间戳到schema_migrations表(适用于只因为它已经有相关的表现有设置)
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)
解决方案
- Edit config/database.rb to point to the database you want copied.
rake db:schema:dump
- Create a blank migration
- Copy the relevant
create_table
lines from the schema dump and paste it into the migration file - Manually insert the migration timestamp into schema_migrations table (this applies to existing setup only as it already has the relevant table)
这篇关于从现有的表生成的ActiveRecord模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文