I have a sqlite3
database in my rails
app which has a development.sqlite3
file. I want to convert the database to mysql
.Here are the steps I take but still I have problems :
1.First I add and install gem 'seed_dump'
to add the data into my seed.rb
(By running rake db:seed:dump
) because I really need to migrate my data .
2.Change the database.yml
configuration to mysql
setting.
development:
adapter: mysql2
encoding: utf8
database: MyDB
username: root
password: ****
production:
adapter: mysql2
encoding: utf8
database: MyDB
username: root
password: ****
3.Run rails db:create
then rails db:schema:load
.
4.Then loading the data from seed by running rake db:seed:dump
The problem is my many to many relations data (which has a table in db schema ) can't be imported in mysql from my seed.rb.
The thing I wanna know is that is there any other safe way to migrate my data from sqlite3
to mysql
instead of writing them into seed.rb
and then read them ?