我使用gem,seed_dump在从计算机移动到计算机时转储和播种数据库。虽然我在播种时能够转储我的数据,但我得到了这个错误:
SyntaxError: /Users/bowser/rails_projects/project_one/db/seeds.rb:7: syntax error, unexpected ']', expecting end-of-input
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/Library/Ruby/Gems/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:543:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.0/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
除了创建文件之外,没有任何代码被更改,这让我想知道它是否正确输出。
种子档案
Article.create!([
{title: "RailsConf", body: "RailsConf is the official gathering for Rails developers..", published_at: "2013-04-13 00:00:00", excerpt: nil, location: nil, user_id: nil},
{title: "Introduction to Active Record", body: "Active Record is Rail's default ORM..", published_at: "2014-08-14 00:00:00", excerpt: nil, location: nil, user_id: nil}
])
#<Class:0x007f92d712a108>.create!([
{article_id: 1, category_id: 1}
])
Category.create!([
{name: "sports"}
])
#<Class:0x007f92d70e2268>.create!([
{article_id: 1, category_id: 1}
])
Profile.create!([
{user_id: nil, name: "Joe", birthday: "2014-08-14", color: "blue", twitter: "twitter.com/joe"}
])
答案 0 :(得分:4)
坏消息!
seed_dump
doesn't work表示没有相应型号的表格,例如HABTM映射表。
在您的情况下,它的HABTM映射器表的问题有article_id
和category_id
列但是根据实现,它没有模型,因此seed_dump
向{添加了错误的代码{1}}
db/seed.rb
当您尝试运行#<Class:0x007f92d70e2268>.create!([
{article_id: 1, category_id: 1}
])
时,它将无效。
替代解决方案:
只需从服务器中提取数据库转储,然后通过将其导入新计算机上的数据库服务器,将其添加到新计算机上。
如果您使用的是rake db:seed
,则需要执行以下操作:
mysql
它会询问你的mysql密码。输入它,它会将数据导出到FILE_NAME.sql
现在在另一台机器上导入db,
mysqldump -u USERNAME -p DATABASE_NAME > FILE_NAME.sql
的更多信息