我有一个小的seed.sql文件,它由一系列INSERT INTO语句组成,例如INSERT INTO posts (title, body) VALUES ("my post title", "the body of the post");
如何将此数据导入我的Rails4 sqlite3数据库?或将其导入我的seed.rb文件?
答案 0 :(得分:2)
只需使用SQLite本身导入它:
sqlite3 db/your_database.sqlite -init path/to/seeds.sql
或者,您可以打开sqlite3 shell,并从那里的文件中读取任何SQL命令,首先运行:
sqlite3 db/your_database.sqlite
然后在sqlite shell中,在sqlite>
提示符下键入:
.read path/to/seeds.sql
这将与-init
选项做同样的事情。