问题描述
我有一个sql脚本文件,在导入时会在MySQL数据库中创建一个表,并用2800条记录填充该表.这些都是比利时国家的邮政编码.
I have a sql script file that upon import creates a table in a MySQL database and fills it with 2800 record. These are all the postal codes for the country Belgium.
现在,我想从中制作一个Ruby on Rails数据库迁移文件.知道我该怎么做吗?
Now I would like to make a Ruby on Rails database migration file from this. Any idea how I can do this?
也许有办法解决?告诉数据库迁移文件执行单独的sql脚本?
Maybe there is a way around? Telling in a database migration file to execute a separate sql script?
谢谢,迈克尔
推荐答案
如果您的config/database.yml使用架构引用了MySQL数据库,则执行
If your config/database.yml is referencing the MySQL database with the schema, then do
rake db:schema:dump
这将创建一个独立于数据库的db/schema.rb文件.
That will create a db/schema.rb file which is database independent.
将schema.rb复制到db/migrate/001_original_schema.rb:
Copy schema.rb into db/migrate/001_original_schema.rb:
class OriginalDatabaseMigration < ActiveRecord::Migration
def self.up
# schema.rb here
end
def self.down
# drop all the tables
end
end
这篇关于我可以从MySQL sql文件生成Rails数据库迁移文件中的ruby吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!