gpt4 book ai didi

ruby-on-rails - rake 数据库 :migrate giving 'unexpected\n' error

转载 作者:数据小太阳 更新时间:2023-10-29 06:51:28 24 4
gpt4 key购买 nike

我使用 Rails 脚手架 使用来自终端的命令制作模型:

rails generate scaffold Venue venueid:string, venueName:string, venueAddress:string, venueCity:string, venueState:string, venueZip:integer, venuePhone:string, venueAge:int

似乎安装或生成一切正常,但是当我运行 rake db:migrate 时,出现以下错误:

rake aborted!
/Users/Banderson/Documents/demo/db/migrate/20130202222224_create_venues.rb:5: syntax error, unexpected '\n'

t.string, :venueName
^
org/jruby/RubyKernel.java:1062:in `require'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
/Users/Banderson/Documents/demo/db/migrate/20130202222224_create_venues.rb:537:in `load_migration'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:533:in `migration'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:528:in `migrate'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:720:in `migrate'
org/jruby/RubyProc.java:270:in `call'
org/jruby/RubyProc.java:220:in `call'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:775:in `ddl_transaction'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/transactions.rb:208:in `transaction'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:775:in `ddl_transaction'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:719:in `migrate'
org/jruby/RubyArray.java:1620:in `each'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:700:in `migrate'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:570:in `up'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/migration.rb:551:in `migrate'
/Users/Banderson/.rvm/gems/jruby-1.6.8/gems/activerecord-3.2.10/lib/active_record/railties/databases.rake:179:in `(root)'
org/jruby/RubyProc.java:270:in `call'
org/jruby/RubyProc.java:220:in `call'
org/jruby/RubyArray.java:1620:in `each'
org/jruby/RubyArray.java:1620:in `each'
org/jruby/RubyKernel.java:1087:in `load'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我做错了什么,或者我该如何解决?

最佳答案

尝试

rails generate scaffold Venue venueid:string venueName:string venueAddress:string venueCity:string venueState:string venueZip:integer venuePhone:string venueAge:int

相反。每个字段之间不应有逗号。

使用逗号,您将在其中生成一个迁移:

create_table :venues do |t|
t.string, :venueid
t.string, :venueName
t.string, :venueAddress
t.string, :venueCity
t.string, :venueState
t.integer, :venueZip
t.string, :venuePhone
t.int :venueAge

t.timestamps
end

如您所见,每个 t.string/integer/etc。方法调用在给出任何参数之前有一个逗号,这是无效的。如果这样做:

puts, "hi"

我得到了错误

syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'

这与您遇到的错误类似。

tldr:不要在生成器中使用逗号

关于ruby-on-rails - rake 数据库 :migrate giving 'unexpected\n' error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14667183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com