在为产品订单创建数据库时,Rails错误,意外的tSYMBEG

时间:2016-01-11 16:50:36

标签: ruby-on-rails database syntax

我正在尝试在rails中创建一个简单的数据库来存储用户和产品ID。

我收到此错误:

from -e:1:in `<main>'2.2.3 :015 > rails g migration create_orders user_id :integer :index product_id :integer :index total :float
SyntaxError: (irb):15: syntax error, unexpected ':', expecting end-of-input
...reate_orders user_id :integer :index product_id :integer :in...
...                               ^
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
    from /Users/TXII/Desktop/nameofapp/bin/rails:9:in `<top (required)>'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/commands/rails.rb:6:in `call'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:183:in `block in serve'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:156:in `fork'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:156:in `serve'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:131:in `block in run'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:125:in `loop'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application.rb:125:in `run'
    from /Users/TXII/.rvm/gems/ruby-2.2.3/gems/spring-1.4.4/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/TXII/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/TXII/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'2.2.3 :016 > rails g migration create_orders user_id:integer:index product_id:integer:index total:float

当我尝试运行此

rails g migration create_orders user_id:integer:index product_id:integer:index total:float

有人知道我在这里做错了什么,我无法确定问题所在。

1 个答案:

答案 0 :(得分:1)

看起来你正试图在rails控制台(或irb)中运行该命令,而它应该从你的shell运行(例如bash)